标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1487 Accepted Submission(s): 567
解题:哎。。连续训练了两个月,身累心更累。。不想说什么了,看这位大神的解说吧
他的钻头是可以突破天际的钻头
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 365; 4 typedef long long LL; 5 const LL mod = 1e9 + 7; 6 LL dp[maxn][maxn],c[maxn][maxn]; 7 void init(){ 8 memset(dp,-1,sizeof dp); 9 for(int i = 0; i < maxn; ++i){ 10 c[i][0] = c[i][i] = 1; 11 for(int j = 1; j < i; ++j) 12 c[i][j] = (c[i-1][j-1] + c[i-1][j])%mod; 13 } 14 } 15 LL dfs(int n,int d){ 16 if(n == 1 && d >= 1) return 1; 17 if(n == 1 || d == 0) return 0; 18 if(dp[n][d] != -1) return dp[n][d]; 19 LL &ret = dp[n][d]; 20 ret = (dfs(n-1,d-1)*c[n][1]*2)%mod; 21 for(int k = 1; k <= n-2; ++k) 22 ret = (ret + (dfs(n-k-1,d-1)*dfs(k,d-1)%mod*c[n-2][k]%mod*c[n][1])%mod)%mod; 23 return ret; 24 } 25 int main(){ 26 int kase,cs = 1,n,d; 27 init(); 28 scanf("%d",&kase); 29 while(kase--){ 30 scanf("%d%d",&n,&d); 31 printf("Case #%d: %I64d\n",cs++,(dfs(n,d) - dfs(n,d-1) + mod)%mod); 32 } 33 return 0; 34 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4782466.html