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

Input

A single line with a single integer, N.

Output

The number of ways to represent N as the indicated sum.
Due to the potential huge size of this number, print only last 9 digits (in
base 10 representation).

Sample Input

7

Sample Output

6


题意:整数N用2^n之和的形式表示的方案数

思路:当N>1时,若N为奇数,则每个分解方案中至少含有一个1项。此时若每种分解方案中去掉一个1项,方案数不发生改变。

   即     N分解的方案数=(N-1)分解的方案数

   若该N为偶数,则分为两类情况:

   1、含有1项,同上,每个方案中去掉1项,方案数不变。

   2、不含有1项,此时每个方案中最小项应为2,若将每一项除2,方案数不变。

   即     N分解的方案数=(N-1)分解的方案数+(N/2)分解的方案数。

边界条件:当N=1时只有一种分解方案。

注意:可能溢出,需要取模


 #include<cstdio>
int s[];
int main()
{
int n; s[]=;
for( int i=; i<=; i++){
if( i%== )
s[i]=(s[i-]+s[i/])%;
else
s[i]=s[i-];
}
while(~scanf("%d",&n)){
printf("%d\n",s[n]);
} return ;
}

DP_Sumsets的更多相关文章

随机推荐

  1. 3-2新建Photoshop图像

    http://www.missyuan.com/thread-350740-1-1.html   [CTRL N][文件 新建] 按住CTRL双击Photoshop的空白区(这个好像是打开文件){快捷 ...

  2. B. Uniqueness(尺取)

    B. Uniqueness time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. Python学习日记(六)——内置函数和文件操作(lambda)

    lambda表达式 学习条件运算时,对于简单的 if else 语句,可以使用三元运算来表示,即: # 普通条件语句 if 1 == 1: name = 'prime' else: name = 'c ...

  4. 测试puppeteer模拟度检测

    var puppeteer = require('puppeteer'); const devices = require('puppeteer/DeviceDescriptors'); const ...

  5. Python进行Redis数据迁移

    Python进行Redis数据迁移 由于开发时的误操作,导致redis数据损坏,所以需要进行redis的数据迁移,网上大佬的教程基本都是需要下载附加工具,亦或是需要一些复杂的操作,个人觉得麻烦还不如写 ...

  6. HearthBuddy 召唤随从的问题

    代码如下,在SilverFish\SilverFish\ai\Playfield.cs文件中 public void callKid(CardDB.Card c, int zonepos, bool ...

  7. SourceTree软件

      A free Git client for Windows and Mac SourceTree 是 Windows 和Mac OS X 下免费的 Git 和 Hg 客户端管理工具,同时也是Mer ...

  8. [java]取当前时间

    /** * Get current date time * * @return */ private static String getCurrTime() { SimpleDateFormat sd ...

  9. java后台服务器向Nodejs客户端发送压缩包文件

    java代码: Map map=new HashMap(); try { //获取本地文件转换成字符换 File file = new File(apppath);//"D:/upload/ ...

  10. MySQL 临时表和复制表

    MySQL 临时表在我们需要保存一些临时数据时是非常有用的.临时表只在当前连接可见,当关闭连接时,Mysql会自动删除表并释放所有空间. 临时表在MySQL 3.23版本中添加,如果你的MySQL版本 ...