前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >1677: [Usaco2005 Jan]Sumsets 求和

1677: [Usaco2005 Jan]Sumsets 求和

作者头像
HansBug
发布2018-04-10 14:28:45
5720
发布2018-04-10 14:28:45
举报
文章被收录于专栏:HansBug's Lab

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,以防万一)

代码语言:javascript
复制
 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.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-12-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1677: [Usaco2005 Jan]Sumsets 求和
  • Description
  • Input
  • Output
  • Sample Input
  • Sample Output
  • HINT
  • Source
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档