NumberPyramids 背包问题
来源:互联网 发布:java局域网聊天软件 编辑:程序博客网 时间:2024/06/10 23:45
源文件 NumberPyramids.*
输入文件 NumberPyramids.in
输出文件 NumberPyramids.out
时限 1S
假设有N个数写成一行,这行上面一行有N-1个数,第i数是第一行第i个数和第i+1个数的和。依次类推,最上面一行为第N行,有一个数。例如,4个数2,1,2,4形成如下结构:
15
6 9
3 3 6
2 1 2 4
我们称这种结构为NumberPyramid。两个NumberPyramid相同当且仅当对应位置上的数相同。
给出两个整数baseLength和top。计算出有多少个不同的仅包含正整数的NumberPyramid,使得NumberPyramid的最高的数为top,第一行有baseLength个数。由于答案可能过大,只需要输出模1,000,000,009的余数即可。
输入
第一行两个整数baseLength,top。
输出
一个整数,题目所求答案。
样例
NumberPyramids.in
3 5
NumberPyramids.out
2
NumberPyramids.in
5 16
NumberPyramids.out
1
数据范围
对于30%的数据,top<=20,baseLength<=5。
对于100%的数据,2<=baseLength<=1,000,000,1<=top<=1,000,000。
背包。。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long int64;
typedef pair<int,int> PII;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double eps=1e-10;
const double pi=acos(-1.0);
const int mod=1000000009;
const int inf=1000000000;
const int dx[]={0,0,-1,1,-1,-1,1,1};
const int dy[]={-1,1,0,0,-1,1,-1,1};
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define sz(A) ((int)A.size())
#define sp system("pause");
int b[30][30],a[30],f[1000010];
int main(){
freopen("NumberPyramids.in","r",stdin);
freopen("NumberPyramids.out","w",stdout);
int n,m;
cin>>n>>m;
if (n>30 || two(n-1)>m){puts("0"); return 0;}
b[1][1]=1;
for (int i=2;i<=n;i++)
for (int j=1;j<=i;j++)
b[i][j]=b[i-1][j-1]+b[i-1][j];
for (int i=1;i<=n;i++) a[i]=b[n][i];
m-=two(n-1);
f[0]=1;
for (int i=1;i<=n;i++)
for (int j=a[i];j<=m;j++)
f[j]=(f[j]+f[j-a[i]])%mod;
cout<<f[m]<<endl;
//system("pause");
}
/*
3 5
*/
- NumberPyramids 背包问题
- HUST1380:NumberPyramids
- 【无限背包】背包问题
- 背包问题---01背包
- 背包问题--部分背包
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 网狐棋牌游戏服务端架构设计原理
- Debian 6.0 安装 KVM 桥接网络
- Java代理类Proxy
- 关于TCP编程,你是否为此迷惑过
- 2011.11.10 poj1062,poj2253,poj1125 单源最短路径 解题报告
- NumberPyramids 背包问题
- hmailserver 及其webmail的配置(仅限局域网内测试)---续
- java间数据的同步(StringBuffer,Map)
- 隐藏任务栏显示
- 在mac上安装ffmpeg
- sql server 2008安装需要一直重启。但重启后又没有达到效果。
- android的窗口机制分析------ViewRoot类
- 使用标签对HTML特殊字符进行转义
- break和continue的用法