1677: [Usaco2005 Jan]Sumsets 求和

1677: [Usaco2005 Jan]Sumsets 求和

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 626  Solved: 348
[Submit][Status]

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) 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

HINT

Source

Silver

题解:呵呵呵呵,又是一道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.
时间: 2024-12-27 22:46:15

1677: [Usaco2005 Jan]Sumsets 求和的相关文章

BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )

完全背包.. --------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #define

bzoj:1677: [Usaco2005 Jan]Sumsets 求和

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+

[BZOJ1677][Usaco2005 Jan]Sumsets 求和

1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1031  Solved: 603 [Submit][Status][Discuss] Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use onl

[BZOJ1679][Usaco2005 Jan]Moo Volume 牛的呼声

1679: [Usaco2005 Jan]Moo Volume 牛的呼声 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1097  Solved: 571 [Submit][Status][Discuss] Description Farmer John has received a noise complaint from his neighbor, Farmer Bob, stating that his cows are making too

BZOJ 1679 [Usaco2005 Jan]Moo Volume 牛的呼声

解法1: N^2的暴力程序,卡卡常数就过了. #include <cstdio> #include <algorithm> #include <cmath> int n; int a[10005]; long long tot; inline bool Read(int &ret){ char c; int flag = 1; if(c=getchar(),c==EOF) return 0; while(c!='-' && (c<'0'||

BZOJ1736 [Usaco2005 jan]The Wedding Juicer 婚宴的榨汁机

从外面一点一点往里面拓展(floodfill),每次找出最小的一个点,计算它对答案的贡献就好了... 找最小的点的话,直接pq就行 1 /************************************************************** 2 Problem: 1736 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:196 ms 7 Memory:2116 kb 8 *******************

【bzoj1737】[Usaco2005 jan]Naptime 午睡时间

题目描述 Goneril is a very sleep-deprived cow. Her day is partitioned into N (3 <= N <= 3,830) equal time periods but she can spend only B (2 <= B < N) not necessarily contiguous periods in bed. Due to her bovine hormone levels, each period has it

BZOJ 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场

Description 大雨侵袭了奶牛们的牧场.牧场是一个R * C的矩形,其中1≤R,C≤50.大雨将没有长草的土地弄得泥泞不堪,可是小心的奶牛们不想在吃草的时候弄脏她们的蹄子.  为了防止她们的蹄子被弄脏,约翰决定在泥泞的牧场里放置一些木板.每一块木板的宽度为1个单位,长度任意.每一个板必须放置在平行于牧场的泥地里.    约翰想使用最少的木板覆盖所有的泥地.一个木板可以重叠在另一个木板上,但是不能放在草地上. Input 第1行:两个整数R和C. 第2到R+1行:每行C个字符,其中"*'代

bzoj1735 [Usaco2005 jan]Muddy Fields 泥泞的牧场

传送门 分析 我们知道对于没有障碍的情况就是将横轴点于纵轴点连边 于是对于这种有障碍的情况我们还是分横轴纵轴考虑 只不过对于有障碍的一整条分为若干个无障碍小段来处理 然后将标号小段连边,跑最大匹配即可 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #includ