NOIP复习赛20161117
题目链接:http://files.cnblogs.com/files/candy99/%E9%A2%98%E7%9B%AE1117.pdf
A
n个等比数列求和公式(都感觉数列忘光了)

%1e9+7要用逆元
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int MOD=1e9+;
int n,m;
ll powMod(ll a,int b){
ll ans=;
for(;b;b>>=,a=(a*a)%MOD)
if(b&) ans=(ans*a)%MOD;
return ans;
}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){
if(b==) {d=a;x=;y=;}
else {exgcd(b,a%b,d,y,x);y-=(a/b)*x;}
}
ll inv(ll a,ll n){
ll d,x,y;
exgcd(a,n,d,x,y);
return d==?(x+n)%n:-;
}
int main(){
scanf("%d%d",&n,&m);
ll ans=m;
for(int i=;i<=n;i++){
ll p=powMod(i,m);
ll tmp=i*(p-)%MOD*inv(i-,MOD)%MOD;
ans=(ans+tmp)%MOD;
}
printf("%lld",ans);
}
B
poj two缩水版,连直径都不用求,求从1开始最长路径
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5e4+;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,u,v,w;
struct edge{
int ne,v,w;
}e[N<<];
int h[N],cnt=;
void ins(int u,int v,int w){
cnt++;
e[cnt].v=v; e[cnt].w=w; e[cnt].ne=h[u]; h[u]=cnt;
cnt++;
e[cnt].v=u; e[cnt].w=w; e[cnt].ne=h[v]; h[v]=cnt;
}
int f[N],sum=;
void dp(int u,int fa){
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v,w=e[i].w;
if(v==fa) continue;
dp(v,u);
f[u]=max(f[u],f[v]+w);
}
}
int main(){
n=read();
for(int i=;i<=n-;i++) u=read(),v=read(),w=read(),ins(u,v,w),sum+=w*;
dp(,);
printf("%d",sum-f[]);
}
C
【问题背景】
zhx和妹子们玩数数游戏。
【问题描述】
仅包含4或7的数被称为幸运数。
一个序列的子序列被定义为从序列中删去若干个数,剩下的数组成的新序列。两个子序列被定义为不同的当且仅当其中的元素在原始序列中的下标的集合不相等。对于一个长度为N的序列,共有2^N个不同的子序列。(包含一个空序列)。
一个子序列被称为不幸运的,当且仅当其中不包含两个相同的幸运数。
对于一个给定序列,求其中长度恰好为K的不幸运子序列的个数,答案mod 10^9+7输出。
【输入格式】
第一行两个正整数N,K,表示原始序列的长度和题目中的K。
接下来一行N个整数ai,表示序列中第i个元素的值。
【输出格式】
仅一个数,表示不幸运子序列的个数。(mod 10^9+7)
【样例输入】
3 2
1 1 1
【样例输出】
3
【样例输入】
4 2
4 7 4 7
【样例输出】
4
【样例解释】
对于样例1,每个长度为2的子序列都是符合条件的。
对于样例2,4个不幸运子序列元素下标分别为:{1, 2}, {3, 4}, {1, 4}, {2, 3}。注意下标集{1, 3}对应的子序列不是“不幸运”的,因为它包含两个相同的幸运数4.
卡读题啊
是序列不是字符串,只含4或7是幸运数字,有两个相同的幸运数字是不幸运序列
搜了题解
幸运数字大约2^10个,可以预处理出来,直接构造不幸运数列
ans=Σ(0<=i<=k) C(n1,i)*f(n2,k-i)
n1是不幸运数字数量,n2是幸运数字数量
f[i][j]表示前i个幸运数字选j个的方案数,一个幸运数字只能选一个,所以需要DP
组合数也需要逆元
PS:构造幸运数字的dfs少写了一层。。。。。。。查了好久
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1e5+,M=1e3+;
const int MOD=1e9+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,k,a,n1,n2;
ll luc[M],cnt=,sum[M];
void dfs(int d,ll now){
if(now) luc[++cnt]=now;
if(d==) return;
dfs(d+,now*+);
dfs(d+,now*+);
}
ll f[N],c[N];
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){
if(b==) {d=a;x=;y=;}
else {exgcd(b,a%b,d,y,x);y-=(a/b)*x;}
}
ll inv(ll a,ll n){
ll d,x,y;
exgcd(a,n,d,x,y);
return d==?(x+n)%n:-;
}
void dp(){
f[]=;
for(int i=;i<=cnt;i++) if(sum[i]>=)
for(int j=i;j>=;j--)
f[j]=(f[j]+f[j-]*sum[i]%MOD)%MOD; c[]=;
for(int i=;i<=n1;i++)
c[i]=c[i-]*(n1-i+)%MOD*inv(i,MOD)%MOD;
}
int main(){
n=read();k=read();
n1=n;
dfs(,);
sort(luc+,luc++cnt);
for(int i=;i<=n;i++){
a=read();
int p=lower_bound(luc+,luc++cnt,a)-luc;
if(luc[p]==a){
sum[p]++; //sum[p]==1 regard as unlucky
if(sum[p]==) n2++,n1-=;
if(sum[p]>) n1--;
}
}
dp();
ll ans=;
for(int i=;i<=k;i++) ans=(ans+c[i]*f[k-i]%MOD)%MOD;
printf("%lld",ans);
}
NOIP复习赛20161117的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
随机推荐
- C#模拟Http请求时出现 基础连接已经关闭 未能为 SSLTLS 安全通道建立信任关系
//解决方法: //引入命名空间: using System.Security.Cryptography.X509Certificates; using System.Net.Security; // ...
- VirtualBox动态添加虚拟硬盘
本文非技术类文章,仅作为记录. 因为使用VirtualBox时遇到这样的问题:原本虚拟机分配存储的80G已经足够了,但是随着使用的文件越来越多,需要的空间也越来越大,因此不得不扩展虚拟机的磁盘容量. ...
- asp.net mvc项目自定义区域
前言 直接上干货就是,就不废话了. 使用场景:分离模块,多站点等~~ 一.分离模块 自定义视图引擎,设置视图路径格式 项目结构图 1.Code: 在Global.asax Application_St ...
- jquery给div的innerHTML赋值
$("#id").html()=""; //或者 $("#id").html("test");
- form表单提交和ajax表单提交,关于移动端如何通过软键盘上的【搜索】和【前进】进行提交操作
[文章来源]由于自己对于form研究甚少,所以一直用的都是AJAX进行提交,这次后台提出要用form提交,顺便深入研究一下:之前在做表单的时候,发现input可以通过设置不同的type属性,调用不同的 ...
- 基于HTML5 Canvas实现的图片马赛克模糊特效
效果请点击下面网址: http://hovertree.com/texiao/html5/1.htm 一.开门见山受美国肖像画家Chuck Close的启发,此脚本通过使用HTML5 canvas元素 ...
- 翻译:常见问题——ABAP Development Tools for Eclipse
ABAP Development Tools for Eclipse(简称ADT)是一个基于Eclipse的全新ABAP IDE,这篇文档试图回答有关ADT的最重要的常见问题.这只是一个开始,如果你对 ...
- 一个有趣的CM
系统 : Windows xp 程序 : Crackme#3 - Self Destructed 程序下载地址 :http://pan.baidu.com/s/1kVxwlaZ 要求 : 注册机编写 ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q131-Q134)
Question 131 You are designing multiple SharePoint 2010 features. You have the following requiremen ...
- iOS之关于 srand() 和rand()
srand(seed)用来将随机序列的起始点设为seed srand((int)time(0))表示以当前时间对应的int值为随机序列起点,这样每次运行程序,由于起点不同才可以得到不同的随机数 tim ...