bzoj 1677 求和
Description
Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7: 1) 1+1+1+1+1+1+1 2) 1+1+1+1+1+2 3) 1+1+1+2+2 4) 1+1+1+4 5) 1+2+2+2 6) 1+2+4 Help FJ count all possible representations for a given integer N (1 <= N <= 1,000,000).
给出一个N(1≤N≤10^6),使用一些2的若干次幂的数相加来求之.问有多少种方法
Input
一个整数N.
Output
方法数.这个数可能很大,请输出其在十进制下的最后9位.
Sample Input
7
Sample Output
6
思路: 本题可以递推
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define R register int 4 #define rep(i,a,b) for(R i=a;i<=b;i++) 5 #define ms(i,a) memset(a,i,sizeof(a)) 6 int const N=1e6+1; 7 int const mod=1e9; 8 int f[N],n; 9 int main(){ 10 scanf("%d",&n); 11 f[0]=1; 12 rep(i,1,n) if(i&1) f[i]=f[i-1]; else f[i]=(f[i-1]+f[i/2])% mod ; 13 cout<<f[n]<<endl; 14 return 0; 15 }