## SP15637 GNYR04H - Mr Youngs Picture Permutations

传送门

Description

``````X X X X X
X X X
X X X
X``````

`````` 1  2  3  4  5     1  5  8 11 12
6  7  8           2  6  9
9 10 11           3  7 10
12                4``````

``123 123 124 124 125 125 126 126 134 134 135 135 136 136 145 146 45 46 35 36 34 36 34 35 25 26 24 26 24 25 26 25 6 5 6 5 6 4 5 4 6 5 6 4 5 4 3 3``

### Output

Solution

\$f[a][b][c][d][e]\$表示第一排已经站了\$a\$个人，第二排站了\$b\$个人.....的方案数

Code

``` 1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #define Rg register
5 #define il inline
6 #define db double
7 #define ll unsigned long long
8 #define go(i,a,b) for(Rg int i=a;i<=b;i++)
9 #define yes(i,a,b) for(Rg int i=a;i>=b;i--)
10 using namespace std;
11 const int N=31;
12 int ct[N],n;
13 ll f[N][N/2+1][N/3+1][N/4+1][N/5+1];
14 int main()
15 {
16     while(scanf("%d",&n),n)
17     {
18         memset(ct,0,sizeof(ct));memset(f,0,sizeof(f));
19         go(i,1,n)scanf("%d",&ct[i]);
20         f[0][0][0][0][0]=1;
21         go(a,0,ct[1])
22             go(b,0,ct[2])
23             go(c,0,ct[3])
24             go(d,0,ct[4])
25             go(e,0,ct[5])
26         {
27             ll t=f[a][b][c][d][e];
28             if(a<ct[1])f[a+1][b][c][d][e]+=t;
29             if(b<ct[2]&&a>b)f[a][b+1][c][d][e]+=t;
30             if(c<ct[3]&&b>c)f[a][b][c+1][d][e]+=t;
31             if(d<ct[4]&&c>d)f[a][b][c][d+1][e]+=t;
32             if(e<ct[5]&&d>e)f[a][b][c][d][e+1]+=t;
33         }
34         printf("%llu\n",f[ct[1]][ct[2]][ct[3]][ct[4]][ct[5]]);
35     }
36     return 0;
37 }```
View Code

0条评论