hdu 4602 Partition
2013-07-23 21:32
429 查看
连接:http://acm.hdu.edu.cn/showproblem.php?pid=4602
题目大意是给你一个数的N的加法构成中另外一个数k的出现次数。如
4=1+1+1+1
4=1+1+2
4=1+2+1
4=2+1+1
4=1+3
4=2+2
4=3+1
4=4
1出现了12次。
这题是赵鹏搞出来的。一个数N可以分成好N个块,如果说N= 5,K= 2 那么则会有(0|0|0|0|0)0|00|0这样的可以出现或者在边上的情况00|或者|00,才能保证有00会出现,因为122中2出现两次,所以不用怕出现重复的情况。
代码:
View Code
题目大意是给你一个数的N的加法构成中另外一个数k的出现次数。如
4=1+1+1+1
4=1+1+2
4=1+2+1
4=2+1+1
4=1+3
4=2+2
4=3+1
4=4
1出现了12次。
这题是赵鹏搞出来的。一个数N可以分成好N个块,如果说N= 5,K= 2 那么则会有(0|0|0|0|0)0|00|0这样的可以出现或者在边上的情况00|或者|00,才能保证有00会出现,因为122中2出现两次,所以不用怕出现重复的情况。
代码:
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define N 1000000007 #define LL __int64 LL mods(LL a,LL b,LL n) { LL ret=1; LL tmp=a; while(b) { if(b&0x1) ret=(ret*tmp)%n; tmp=(tmp*tmp)%n; b>>=1; } return ret; } int main() { LL n,k,T; //freopen("data.in","r",stdin); // freopen("data.out","w",stdout); cin>>T; while(T--) { scanf("%I64d%I64d",&n,&k); if(k > n) { printf("0\n"); } else { LL ans = 0; ans = mods(2,n-k,N); if(n-k-1 >= 1) ans += mods(2,n-k-2,N)*(n-k-1); ans %= N; printf("%I64d\n",ans); } } return 0; }
View Code
相关文章推荐
- hdu 4602 Partition(计数)
- HDU 4602 Partition 组成n的方案中k有几个 (好题!!!!找规律题+快速幂)
- 【五边形定则应用2】HDU 4602——Partition
- hdu_4602 Partition
- HDU 4602 Partition (快速幂+思维)
- HDU 4602 - Partition
- 【HDU 4602】Partition
- [HDU 4602]Partition[划分]
- 2013 多校第一场 hdu 4602 Partition
- hdu 4602 Partition (概率方法)
- HDU 4602 Partition
- hdu 4602 Partition(矩阵快速幂乘法)
- hdu 4602 Partition
- hdu 4602 Partition
- HDU 4602 Partition
- HDU 4602 Partition(快速幂)
- HDU 4602 Partition
- HDU 4602 Partition (整数拆分&找规律&快速幂取模)
- hdu-4602-Partition
- hdu-4602-Partition(矩阵快速幂)