Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 626 Solved: 348
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的若干次幂的数相加来求之.问有多少种方法
一个整数N.
方法数.这个数可能很大,请输出其在十进制下的最后9位.
7
6 有以下六种方式 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
题解:呵呵呵呵,又是一道DP题,显然,当n为奇数时,a[n]=a[n-1],当n为偶数时,a[n]=a[n-1]+a[n div 2](特别注意:题目中N的范围限制是6个0,一开始数组开的是5个0害得我RE了2次,记得mod 1000000000,还有最好a[0]设定为1,以防万一)
1 var
2 i,j,k,l,m,n:longint;
3 a:array[0..2000000] of int64;
4 begin
5 readln(n);
6 a[0]:=1;
7 a[1]:=1;
8 for i:=2 to n do
9 begin
10 a[i]:=a[i-1];
11 if not(odd(i)) then a[i]:=(a[i]+a[i div 2]) mod 1000000000;
12 end;
13 writeln(a[n]);
14 end.