1079: [SCOI2008] Coloring scheme
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1123 Solved: 707
Description
There are n pieces of wood lined up, numbered from left to right in 1~n. You have a k color of paint, wherein the first color of the paint is enough to tu ci a wood block. All the paint is just enough to fill all the pieces of wood, namely c1+c2+...+ck=n. Adjacent two pieces of wood painted the same color looks very ugly, so you want to count any two adjacent wood color different coloring scheme.
Input
The first behavior is a positive integer k, the second line contains k integers c1, c2, ..., CK.
Output
Outputs an integer, which is the result of modulo 1,000,000,007 for the total number of scenarios.
Sample Input
31 2 3
Sample Output
10
HINT
100%的数据满足:1 <= k <= 15, 1 <= ci <= 5
Exercises
Dp. Set F[last][a][b][c][d][e] indicates that the last lattice color, at this time can also brush 1 of the color of the lattice has a species, you can also brush 2 of the color of the lattice has B and so on.
Transfer:
If a is not zero, it is transferred to F[1][a-1][b][c][d][e].
If B is not zero, it is transferred to F[2][a+1][b-1][c][d][e].
The other same.
Note: If last equals a then the number of scenarios in the transfer of a will be reduced by 1 (in order to avoid the same color adjacent).
Code:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace Std;#define M 1000000007LLintn,k,a[6]={0}; Long Long f[ -][ -][ -][ -][ -][ -];intIn () {int x=0; Char Ch=getchar (); while(ch<' 0 '|| Ch>' 9 ') Ch=getchar (); while(ch>=' 0 '&& ch<=' 9 ')x=x*10+ch-' 0 ', Ch=getchar ();return x;} Long Long DP (int Last,intAintBintCintDintE) {Long long*s=&f[ Last][a][b][c][d][e];if(! (a+b+c+d+e)) {*s=1;return 1; }//cout<< Last<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<*s<<endl;if(*s)return *s;if(a)*s=(*s+ (A-( Last==2))*DP(1, A-1, b,c,d,e))%M;if(b)*s=(*s+ (b-( Last==3))*DP(2, A +1, B-1, c,d,e))%M;if(c)*s=(*s+ (C ( Last==4))*DP(3, a,b+1, C-1, d,e))%M;if(d)*s=(*s+ (d ( Last==5))*DP(4, a,b,c+1, d1, e))%M;if(e)*s=(*s+ (E*DP(5, a,b,c,d+1, E-1)))%M;return *s;}intMain () {k=in ();int x; for(intI=1; i<=k; i++)x=in (), a[x]++; Memset (F,0, sizeof (f));printf("%lld\ n", DP (0, a[1],a[2],a[3],a[4],a[5]));return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"DP" "Bzoj 1079" "Scoi 2008" coloring scheme