您的位置:首页 > 其它

【codechef】Steady tables(dp)

2015-06-16 23:07 337 查看


Input:
3
1 1
2 2
2 3
Output:
2
25
273


Explanation

Test case 1 : There are only 2 such grids possible 0 and 1.
http://www.codechef.com/JUNE15/problems/STDYTAB

这题没考虑到DP是我的错。。一直以为是推规律。。

#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define ll long long
using namespace std;
ll mod=1000000000;
ll C[4005][2005];
ll dp[2005][2005];
int main(){
	for(int i=0;i<=4000;++i){
		for(int j=0;j<=2000;++j){
			if(j==0||i==j)
				C[i][j]=1;
			else
				C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
		}
	}
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		for(int j=0;j<=m;++j) //注意初始化条件 
			dp[0][j]=1;
		for(int i=1;i<=n;++i){
			for(int j=0;j<=m;++j){
				dp[i][j]=(dp[i-1][j]*C[j+m-1][m-1])%mod;
				dp[i][j]=(dp[i][j-1]+dp[i][j])%mod;
			}
		}
		cout<<dp
[m]<<endl;
	} 
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: