国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

POJ2229-Sumsets-完全背包

2019-11-08 18:25:46
字體:
來源:轉載
供稿:網友

原題鏈接 Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 17986 Accepted: 7052 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 Source

USACO 2005 January Silver

#include <cstdio>#include <iostream>using namespace std;const int maxn = 1000000 + 10;long long dp[maxn];int main(){ int n; cin >> n; dp[1]=1; for(int i=2;i<=n;i++){ if(i&1) dp[i]=dp[i-1]; else dp[i] = (dp[i/2] + dp[i-1])%1000000000; cout << i << ":" << dp[i] << endl; } cout << dp[n] << endl; return 0;}/*下面是完全背包的做法#include <cstdio>#include <iostream>using namespace std;const int maxn = 1000000 + 10;const int mod=1e9;int dp[maxn];int main(){ int n; cin >> n; dp[0]=1; for(int i=1;i<21;i++){ int v=(1<<(i-1)); for(int j=v;j<=n;j++){ dp[j] = dp[j] + dp[j-v]; while(dp[j]>mod) dp[j]-=mod; } } cout << dp[n] << endl;}// i 0 1 2 3 4 5// v[i] 1 2 4 8 16 32// i/j 0 1 2 3 4 5 6 7// 0 0 0 0 0 0 0 0 0 i:1~ceiling j:v[i-1]~n// 1 1 1 1 1 1 1 1 1 dp[j] = dp[j] + dp[j-v[i-1]]; v[i-1]<= j <=n;// 2 1 1 2 2 3 3 4 4 // 3 1 1 2 2 4 4 6 6// 4 1 1 2 2 4 4 6 6*/
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苗栗县| 饶平县| 白银市| 金华市| 大港区| 如皋市| 巴中市| 云龙县| 翁源县| 古田县| 商都县| 城市| 乌什县| 温宿县| 英德市| 新和县| 确山县| 长寿区| 乐清市| 聊城市| 柘城县| 钟祥市| 衡东县| 英吉沙县| 大洼县| 察哈| 五华县| 罗源县| 济南市| 和平区| 许昌县| 中卫市| 清水河县| 舞阳县| 自治县| 页游| 慈利县| 留坝县| 武宁县| 连山| 铁岭县|