#include<iostream>
using namespace std;
typedef long long ll;
ll k; //k row
ll n[10]; // number of each row
ll dp[31][31][31][31][31];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
while(cin >> k)
{
if(k == 0) break;
for(ll i = 1; i <= k; ++i)
cin >> n[i];
if(k < 5){
for(ll i = k+1; i <= 5; ++i)
n[i] = 0;
}
for(ll i = 0; i <= n[1]; ++i)
for(ll j = 0; j <= n[2]; ++j)
for(ll m = 0; m <= n[3]; ++m)
for(ll a = 0; a <= n[4]; ++a)
for(ll b = 0; b <= n[5]; ++b)
dp[i][j][m][a][b] = 0;
dp[0][0][0][0][0] = 1;
for(ll a = 0; a <= n[1]; ++a){
for(ll b = 0; b <= min(n[2], a); ++b){
for(ll c = 0; c <= min(n[3], b); ++c){
for(ll d = 0; d <= min(n[4], c); ++d){
for(ll e = 0; e <= min(n[5], d); ++e){
if(a < n[1]) dp[a+1][b][c][d][e] += dp[a][b][c][d][e];
if(b < a && b < n[2]) dp[a][b+1][c][d][e] += dp[a][b][c][d][e];
if(c < b && c < n[3]) dp[a][b][c+1][d][e] += dp[a][b][c][d][e];
if(d < c && d < n[4]) dp[a][b][c][d+1][e] += dp[a][b][c][d][e];
if(e < d && e < n[5]) dp[a][b][c][d][e+1] += dp[a][b][c][d][e];
}
}
}
}
}
cout << dp[n[1]][n[2]][n[3]][n[4]][n[5]] << endl;
}
return 0;
}
poj 2279 Mr. Young's Picture Permutations(线性DP)
最新推荐文章于 2021-11-07 13:39:23 发布