poj -2229 Sumsets (dp)
http://poj.org/problem?id=2229
题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数。问你不同方案数之和是多少?
n很大,所以输出后9位即可。
dp[i] 表示组成i的不同方案数,那么 dp[1]=1;dp[2]=2;
if(i%2) dp[i]=dp[i-1] ; i如果是奇数,那么只能在i-1的每个方案数前面加上1得到i,所以方案数相等。
else dp[i]=dp[i-1]+dp[i/2] ; i如果是偶数,一种可能是i有两个1,在i-1的每个方案前面加上1,,还有一种是i全部偶数的情况,那么可以由dp[i/2]推出。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 1000000
#define mod 1000000000
using namespace std; int n;
long long dp[N]; int main()
{
//Read();
dp[]=;dp[]=;
for(int i=;i<=N;i++)
{
if(i%) dp[i]=dp[i-];
else dp[i]=(dp[i-]+dp[i/])%mod;
}
scanf("%d",&n);
printf("%d\n",dp[n]);
return ;
}
poj -2229 Sumsets (dp)的更多相关文章
- poj 2229 Sumsets(dp)
Sumsets Time Limit : 4000/2000ms (Java/Other) Memory Limit : 400000/200000K (Java/Other) Total Sub ...
- poj 2229 Sumsets(dp 或 数学)
Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...
- POJ 2229 Sumsets(规律)
这是一道意想不到的规律题............或许是我比较菜,找不到把. Description Farmer John commanded his cows to search for diffe ...
- POJ 2229 Sumsets(递推,找规律)
构造,递推,因为划分是合并的逆过程,考虑怎么合并. 先把N展开成全部为N个1然后合并,因为和顺序无关,所以只和出现次数有关情况有点多并且为了避免重复,分类,C[i]表示序列中最大的数为2^i时的方案数 ...
- POJ 2229 Sumsets(找规律,预处理)
题目 参考了别人找的规律再理解 /* 8=1+1+1+1+1+1+1+1+1 1 8=1+1+1+1+1+1+1+2 2 3 8=1+1+1+1+2+2 8=1+1+1+1+4 4 5 8=1+1+2 ...
- POJ 3034 Whac-a-Mole(DP)
题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在( ...
- POJ 2229 Sumsets【DP】
题意:把n拆分为2的幂相加的形式,问有多少种拆分方法. 分析:dp,任何dp一定要注意各个状态来源不能有重复情况.根据奇偶分两种情况,如果n是奇数则与n-1的情况相同.如果n是偶数则还可以分为两种情况 ...
- poj 3230 Travel(dp)
Description One traveler travels among cities. He has to pay for this while he can get some incomes. ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
随机推荐
- Ionic 安装部署
Ionic 安装部署 准备工作 下载安装Node.js, JDK,Apache Ant,Android SDK:编辑器用WebStorm node jdk ant 均需要加进 环境变量path中 An ...
- 【转载】C++编译出现 error C2664: 不能将参数 2 从“const char [5]”转换为“LPCTSTR”解决办法。
编译程序的时候出现这样的错误,原因是在新建MFC项目的时候,设置字符集Unicode的属性. 解决方法一: 在VC2010的解决方案管理器窗口内,右击你的项目“项目”,然后选“属性”(最后一项),再点 ...
- [百度空间] [note] pointer to member is a POD type
C++03 3.9-10: 1 Arithmetic types (3.9.1), enumeration types, pointer types, and pointer to member ty ...
- 浅谈c#枚举
结构中的成员可以赋值,枚举呢....是取值,只读的 以下情况可以考虑将类创建为结构:(1)如果一个类其中的字段非常少,所有字段占用的内存总量不超过8.16字节:(2)如果一个类中的字段都是值类型: 关 ...
- MyEclipse提示键配置、提示快捷键、提示背景色、关键字颜色、代码显示、编...
1.提示键配置 一般默认情况下,Eclipse ,MyEclipse 的代码提示功能是比Microsoft Visual Studio的差很多的,主要是Eclipse ,MyEclipse本身有很多选 ...
- Codeforces Round #259 (Div. 2)-D. Little Pony and Harmony Chest
题目范围给的很小,所以有状压的方向. 我们是构造出一个数列,且数列中每两个数的最大公约数为1; 给的A[I]<=30,这是一个突破点. 可以发现B[I]中的数不会很大,要不然就不满足,所以B[I ...
- nodejs的安装和配置
上次我们介绍了nodeJs入门的一些概念包括nodeJs.npm.express,这次我们介绍在linux的安装以及配置过程 目录: 1 如何在 Linux.Windows上通过包或包管理器安装 No ...
- Why we have to use epsg:900913 in OpenLayers
reference:http://docs.openlayers.org/library/spherical_mercator.html epsg:900913 is spicfy the Soher ...
- Sqli-labs less 31
Less-31 Less-31与上述两个例子的方式是一样的,我们直接看到less-31的sql语句: 所以payload为: http://127.0.0.1:8080/sqli-labs/Less- ...
- D3D Deferred Shading
在3D图形计算中,deferred shading是一个基于屏幕空间的着色技术.之所以被称为deferred shading,是因为我们将场景的光照计算与渲染"deferred"到 ...