Created
January 12, 2014 22:44
-
-
Save mishadoff/8391690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <fstream> | |
#include <string> | |
#include <vector> | |
#include <deque> | |
#include <queue> | |
#include <stack> | |
#include <set> | |
#include <map> | |
#include <algorithm> | |
#include <functional> | |
#include <utility> | |
#include <bitset> | |
#include <cmath> | |
#include <cstdlib> | |
#include <ctime> | |
#include <cstdio> | |
using namespace std; | |
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++) | |
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) | |
typedef long long ll; | |
#define MOD 1000000007ll | |
int N; | |
int a[110]; | |
ll dp[110][110]; | |
ll perm(ll N, ll K){ | |
int i; | |
ll ans = 1; | |
REP(i,K) ans = ans * (N - i) % MOD; | |
return ans; | |
} | |
ll comb(ll N, int K){ | |
int i; | |
ll ans = perm(N, K); | |
for(i=1;i<=K;i++){ | |
while(ans % i != 0) ans += MOD; | |
ans /= i; | |
} | |
return ans; | |
} | |
void main2(void){ | |
int i,j,p,q; | |
cin >> N; | |
REP(i,N) cin >> a[i]; | |
int S = 0; | |
REP(i,N) S += a[i]; | |
REP(i,N+1) REP(j,S+1) dp[i][j] = 0; | |
dp[N][0] = 1; | |
for(i=N-1;i>=0;i--) REP(j,S+1) REP(p,a[i]+1) REP(q,a[i]+1){ | |
if(p > j || q > j) continue; | |
ll coef = comb(a[i], p) * perm(j, p) % MOD * comb(a[i], q) % MOD * perm(j, q) % MOD; | |
if(j+a[i]-p-q <= S) dp[i][j] = (dp[i][j] + coef * dp[i+1][j+a[i]-p-q]) % MOD; | |
} | |
cout << dp[0][0] << endl; | |
} | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
int main(void){ | |
int T,t; | |
cin >> T; | |
REP(t,T){ | |
printf("Case #%d: ", t+1); | |
main2(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment