poj 2229 Sumsets(dp 或 数学)
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 . Here are the possible sets of numbers that sum to : ) ++++++
) +++++
) ++++
) +++
) +++
) ++ Help FJ count all possible representations for a given integer N ( <= N <= ,,).
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 digits (in base representation).
Sample Input
Sample Output
Source
如果i为奇数,肯定有一个1,把f[i-1]的每一种情况加一个1就得到fi,所以f[i]=f[i-1]
如果i为偶数,如果有1,至少有两个,则f[i-2]的每一种情况加两个1,就得到i,如果没有1,则把分解式中的每一项除2,则得到f[i/2]
所以f[i]=f[i-2]+f[i/2]
由于只要输出最后9个数位,别忘记模1000000000
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define N 1010006
#define MOD 1000000000
int n;
int dp[N];
void init(){ dp[]=;
dp[]=;
for(int i=;i<N;i++){
if(i&){
dp[i]=dp[i-];
}
else{
dp[i]=dp[i-]+dp[i/];
dp[i]%=MOD;
}
}
}
int main()
{
init();
while(scanf("%d",&n)==){ printf("%d\n",dp[n]); }
return ;
}
poj 2229 Sumsets(dp 或 数学)的更多相关文章
- poj 2229 Sumsets DP
题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+ ...
- poj -2229 Sumsets (dp)
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...
- poj 2229 Sumsets(dp)
Sumsets Time Limit : 4000/2000ms (Java/Other) Memory Limit : 400000/200000K (Java/Other) Total Sub ...
- poj 2229 Sumsets(记录结果再利用的DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 将一个数N分解为2的幂之和共有几种分法? 题解: 定义dp[ i ]为数 i 的 ...
- POJ 2229 Sumsets【DP】
题意:把n拆分为2的幂相加的形式,问有多少种拆分方法. 分析:dp,任何dp一定要注意各个状态来源不能有重复情况.根据奇偶分两种情况,如果n是奇数则与n-1的情况相同.如果n是偶数则还可以分为两种情况 ...
- POJ 2229 Sumsets
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 11892 Accepted: 4782 Descrip ...
- poj 2229 Sumsets 完全背包求方案总数
Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum ...
- POJ 2229 Sumsets(技巧题, 背包变形)
discuss 看到有人讲完全背包可以过, 假如我自己做的话, 也只能想到完全背包了 思路: 1. 当 n 为奇数时, f[n] = f[n-1], 因为只需在所有的序列前添加一个 1 即可, 所有的 ...
- POJ 2229 计数DP
dp[i]代表是数字i的最多组合数如果i是一个奇数,i的任意一个组合都包含1,所以dp[i] = dp[i-1] 如果i是一个偶数,分两种情况讨论,一种是序列中包含1,因此dp[i]=dp[i-1]一 ...
随机推荐
- python高级编程之我不测试
# -*- coding: utf-8 -*-__author__ = 'Administrator'#测试驱动开发(高级编程处学习,第11章)#测试驱动开发也叫TDD, 是制造高质量软件的一种简单技 ...
- Python安装MySQLdb并连接MySQL数据库
当然了,前提是你已经安装了Python和MySQL.我的Python是2.6版本的. Python2.6的“Set”有点兼容性问题,自己照着改一下: http://sourceforge.net/fo ...
- 关于C#中的弱引用
本文前部分来自:http://www.cnblogs.com/mokey/archive/2011/11/24/2261605.html 分割线后为作者补充部分. 一:什么是弱引用 了解弱引用之前,先 ...
- c++读取ccbi
loader类文件: 需要定义CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(ButtonTestLayerLoader, loader); 这个宏定义是定义静态的l ...
- Unity怎样在Editor下运行协程(coroutine)
在处理Unity5新的AssetBundle的时候,我有一个需求,须要在Editor下(比方一个menuitem的处理函数中,游戏没有执行.也没有MonoBehaviour)载入AssetBundle ...
- Verilog 读写文件
Verilog 读写文件 在数字设计验证中,有时我们需要大量的数据,这时可以通过文件输入,有时我们需要保存数据,可以通过写文件保存. 读写文件testbench module file_rw_tb() ...
- GDI+(Graphics Device Interface)例子
使用SolidBrush 单色画笔 Bitmap bitmap = new Bitmap(800, 600); Graphics graphics = Graphics.From ...
- Material Calendar View 学习记录(二)
Material Calendar View 学习记录(二) github link: material-calendarview; 在学习记录一中简单翻译了该开源项目的README.md文档.接下来 ...
- Java关键字transient和volatile
transient标记的变量,在进行序列化的时候,这个字段不进行序列化操作. volatile标记的变量,在进行读写时,必须强制的与内存同步,即在读的时候需要从内存中读取,写的时候也需要回写到内存中. ...
- select radio readonly
首先 select radio 设置 disable的会无法提交数据. 这让我很头疼 而且 readonly 无效 后来发现.我把自己绕进去了..一般涉及 只读都是 不让用户修改 .而后台只更新 可 ...