【bzoj1677】[Usaco2005 Jan]Sumsets 求和
来源:互联网 发布:西部数码域名管理 编辑:程序博客网 时间:2024/05/22 09:42
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+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
有以下六种方式
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
#include<iostream>#include<cstdio>using namespace std;const int maxn = 1000010;int n,a[100],f[maxn];int main(){scanf("%d",&n);f[0] = 1;int len = 0;for (int i = 1; i <= n; i *= 2)a[++len] = i;for (int i = 1; i <= len; i++)for (int j = a[i]; j <= n; j++)f[j] = (f[j] + f[j-a[i]]) % 1000000000;printf("%d",f[n]);return 0;}
0 0
- bzoj1677[Usaco2005 Jan]Sumsets 求和
- [BZOJ1677] [Usaco2005 Jan]Sumsets 求和
- BZOJ1677: [Usaco2005 Jan]Sumsets 求和
- 【bzoj1677】[Usaco2005 Jan]Sumsets 求和
- bzoj1677:[Usaco2005 Jan]Sumsets 求和
- bzoj1677 [Usaco2005 Jan]Sumsets 求和(递推)
- 1677: [Usaco2005 Jan]Sumsets 求和
- 【BZOJ】1677: [Usaco2005 Jan]Sumsets 求和
- BZOJ 1677:[Usaco2005 Jan]Sumsets 求和
- bzoj 1677: [Usaco2005 Jan]Sumsets 求和(DP)
- bzoj1677
- bzoj1679[Usaco2005 Jan]Moo Volume 牛的呼声
- 【BZOJ 1679】 [Usaco2005 Jan]Moo Volume 牛的呼声
- BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声
- bzoj 1679 [Usaco2005 Jan]Moo Volume 牛的呼声
- bzoj 1737: [Usaco2005 jan]Naptime 午睡时间 (DP)
- [BZOJ1737][Usaco2005 jan]Naptime 午睡时间(dp)
- bzoj1735[Usaco2005 jan]Muddy Fields 泥泞的牧场
- JS跨域解决方案
- Tensorflow读取数据2-tfrecord
- Nessus漏洞扫描工具安装
- 二叉树的层次遍历
- kaggle入门篇二【Titanic】
- 【bzoj1677】[Usaco2005 Jan]Sumsets 求和
- 五.SpringMVC+MyBatis搭建安全与性能
- 116. Populating Next Right Pointers in Each Node
- IntelliJ IDEA 注册
- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-o2julgbe/xgboost/
- 《程序员修炼之道》笔记(一)
- 地狱飞龙 [simpson][积分]
- Grid绘制(gdi+)
- 有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数? 都是多少?