CDOJ 631 敢说敢做 记忆化搜索and动规

//跟沈爷学的 传送门http://www.cnblogs.com/Xiper/p/4639636.html

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; const long long MOD=; long long n,k;
long long C[][];
long long dp[][]; long long dfs(long long x,long long y){
if (dp[x][y]!=-) return dp[x][y];
if (x== && y==) return ;
if (x!= && y==) return ;
dp[x][y]=;
for (long long i=;i<=x-y+;i++){
dp[x][y]=(dp[x][y]+dfs(x-i,y-)*C[x][i]%MOD)%MOD;
}
return dp[x][y];
} int main(){
memset(dp,-,sizeof(dp));
memset(C,,sizeof(C));
for (long long i=;i<=;i++) C[i][]=;
for (long long i=;i<=;i++){
for (long long j=;j<=;j++){
C[i][j]=(C[i-][j]+C[i-][j-])%MOD;
}
}
while (scanf("%lld%lld",&n,&k)==){
printf("%lld\n",dfs(n,k));
}
return ;
}
/*
1 1
2 2
*/
上一篇:微信开发中网页授权access_token与基础支持的access_token异同


下一篇:预定义异常 - PHP手册笔记