【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; }
相关文章推荐
- SpringMVC理解之一:应用上下文webApplicationContext
- 菜鸟学Android笔记(三十六):JSP入门
- ReactiveCocoa & MVVM 学习总结一
- IOS Exception2 this class is not key value coding-compliant for the key Click
- Python HAIL CAESAR (凯撒密码) 3
- 小心使用replicate_do_db和replicate_ignore_db
- JS正则表达式详解
- 学习Python4(hashlib)
- leetcode刷题。记录,总结,备忘。217
- 语音模仿相似度评价系统
- 2015061606 - 提交时让回车键触发事件失效
- Objective-c学习笔记3
- VsSharp:一个VS扩展开发框架(上)
- ID3算法 决策树 C++实现
- jQuery插件
- 下面是20个非常有用的Java程序片段,希望能对你有用(转载自http://www.codeceo.com/article/20-java-code.html)
- Java基础(二)
- logical vs physical address
- 【图像处理】数字图像处理软件(一)
- hadoop配置中遇到的问题