POJ 2229 Sumsets
2015-06-20 13:42
375 查看
Sumsets
Time Limit: 2000MS Memory Limit: 200000K
Total Submissions: 14323 Accepted: 5699
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).
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
这道题就属于找规律的题了,在场上遇到这种题,很容易就放弃了,因为没有思路,这时候就采用打表的方式去做题,当着这道题计算机不能计算,得手算,得到结果之后看到规律。
Time Limit: 2000MS Memory Limit: 200000K
Total Submissions: 14323 Accepted: 5699
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).
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
这道题就属于找规律的题了,在场上遇到这种题,很容易就放弃了,因为没有思路,这时候就采用打表的方式去做题,当着这道题计算机不能计算,得手算,得到结果之后看到规律。
#include <iostream> #include <cstdio> using namespace std; int a[1000005]; int main(void) { a[1]=1; for(int i=2;i<=1000000;i++) { if(i%2==0) a[i]=a[i-1]+a[i/2]; else a[i]=a[i-1]; a[i]%=1000000000; } int n; scanf("%d",&n); printf("%d\n",a ); return 0; }
相关文章推荐
- HDOJ 5269 ZYB loves Xor I
- 围住浮动元素的三种方法
- 暂时不更新博客
- jxta-P2P学习
- LeetCode之“散列表”:Two Sum && 3Sum && 3Sum Closest && 4Sum
- CF E. Vanya and Brackets(添加一对括号使得表达式的值最大)
- Java串口通信详细解释
- java产生任意范围内不重复的随机数
- Codeforces Round #260 (Div. 1) C. Civilization 并查集,直径
- 黑马程序员--java学习笔记第七天
- VS中的活动debug和活动cpu
- leetcode--Roman to Integer
- Explicit keyword
- 【安德鲁斯】基于脚本的数据库"增量更新",如果不改变,每次更新java代码、!
- Spring中的AOP简述
- win7硬盘安装ubuntu双系统的方法
- 游戏有这么好玩么?
- USACO——Milking Cows 挤牛奶
- 如何在 Ubuntu/Debian/Linux Mint 中编译和安装 wxWidgets
- JavaScript里call,apply,bind方法简介