hdu 4532 湫秋系列故事——安排座位
2013-04-16 21:32
225 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4532
细节决定成败呀 ( x * ( y * z ) % mod ) % mod
刚开始想的是 先 ( y * z ) 对 mod 取模 然后再 *x 对mod取模
后来一想不对呀 (y * z ) 要先 *x 后取模呀
脑子短路伤不起呀
dp+数学
代码:
细节决定成败呀 ( x * ( y * z ) % mod ) % mod
刚开始想的是 先 ( y * z ) 对 mod 取模 然后再 *x 对mod取模
后来一想不对呀 (y * z ) 要先 *x 后取模呀
脑子短路伤不起呀
dp+数学
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<set> #include<map> #include<vector> #include<queue> #include<stack> #define LL long long using namespace std; const int N=500; const long long MOD = 1000000007; int a ; long long dp ; long long c ; long long d ; int main() { //freopen("data.in","r",stdin); for(int i=0;i<N;++i) for(int j=0;j<=i;++j) { if(j==0||i==j) c[i][j]=1; else c[i][j]=(c[i-1][j-1]+c[i-1][j])%MOD; } d[0]=1; for(int i=1;i<N;++i) d[i]=(d[i-1]*i)%MOD; int T; cin>>T; for(int w=1;w<=T;++w) { int n; cin>>n; for(int i=0;i<n;++i) cin>>a[i]; memset(dp,0,sizeof(dp)); dp[0][a[0]-1]=d[a[0]]; int sum=a[0]; for(int i=0;i<n-1;++i) { for(int j=0;j<sum;++j) { if(dp[i][j]>0) { for(int l=0;l<=j&&l<=a[i+1];++l) { for(int r=0;r<=(sum+1-j)&&l+r<=a[i+1];++r) { if(l+r==0) continue; int J=(j-l)+(a[i+1]-l-r); //dp[i+1][J]=(dp[i+1][J]+(dp[i][j]*(c[j][l]*(c[sum+1-j][r]*(d[a[i+1]]*c[a[i+1]-1][l+r-1])%MOD)%MOD)%MOD)%MOD)%MOD; dp[i+1][J]=(((((c[a[i+1]-1][l+r-1]*d[a[i+1]])%MOD*c[sum+1-j][r])%MOD*c[j][l])%MOD*dp[i][j])%MOD+dp[i+1][J])%MOD; } } } } sum+=a[i+1]; } printf("Case %d: ",w); cout<<dp[n-1][0]<<endl; } return 0; }
相关文章推荐
- HDU-4532 湫秋系列故事——安排座位 组合数学DP
- HDU 4532 湫秋系列故事——安排座位(组合)
- HDU 4532 湫秋系列故事——安排座位(组合DP)
- HDU - 4532 湫秋系列故事――安排座位
- HDU - 4532 湫秋系列故事――安排座位 (组合数dp)
- [2013腾讯马拉松复赛第一场]HDU 4532 湫秋系列故事——安排座位
- [组合数 DP] HDU 4532 湫秋系列故事——安排座位
- 【HDU 3208】 组合数学+动态规划 湫秋系列故事——安排座位
- 组合dp hud-4532-湫秋系列故事——安排座位
- HDU 湫秋系列故事——安排座位 组和DP
- hdu 湫秋系列故事——安排座位(组合dp)
- 湫秋系列故事——安排座位
- 湫秋系列故事——安排座位
- HDU 4532 湫秋系列故事——安排座位 (组合+DP)
- HDU 4502 吉哥系列故事——临时工计划(时间安排的01背包)
- HDU 小明系列故事——师兄帮帮忙 快速幂
- hdu 4535 吉哥系列故事——礼尚往来
- Hdu 4507 吉哥系列故事——恨7不成妻 (数位DP)
- hdu 4500 小Q系列故事——屌丝的逆袭
- hdu-4508-湫湫系列故事——减肥记I-dp-java