bzoj 1079 [SCOI2008]着色方案 dp
2016-11-23 18:38
387 查看
设f[][][][][][]表示剩余个数为1~5的颜色的种类数和上次选的颜色的剩余个数。
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long ll f[16][16][16][16][16][6],num[6]; bool vis[16][16][16][16][16][6]; int n; ll F(int x1,int x2,int x3,int x4,int x5,int num) { if(x1+x2+x3+x4+x5==0)return 1; ll &t=f[x1][x2][x3][x4][x5][num]; bool &t1=vis[x1][x2][x3][x4][x5][num]; if(t1)return t; if(x1)t+=(x1-(num==2))*F(x1-1,x2,x3,x4,x5,1); if(x2)t+=(x2-(num==3))*F(x1+1,x2-1,x3,x4,x5,2); if(x3)t+=(x3-(num==4))*F(x1,x2+1,x3-1,x4,x5,3); if(x4)t+=(x4-(num==5))*F(x1,x2,x3+1,x4-1,x5,4); if(x5)t+=x5*F(x1,x2,x3,x4+1,x5-1,5); t1=1;return t%=mod; } int main() { //freopen("tt.in","r",stdin); scanf("%d",&n); for(int i=1,x;i<=n;i++) scanf("%d",&x),num[x]++; printf("%lld\n",F(num[1],num[2],num[3],num[4],num[5],0)); return 0; }
相关文章推荐
- 【dp】【bzoj 1079】【SCOI 2008】着色方案
- 【BZOJ1079】[SCOI2008]着色方案【计数DP】【奇怪的姿势】
- BZOJ 1079: [SCOI2008]着色方案( dp )
- [BZOJ1079][SCOI2008]着色方案 dp
- BZOJ 1079: [SCOI2008]着色方案 神奇的DP
- [BZOJ1079][SCOI2008][DP]着色方案
- [BZOJ1079]SCOI2008着色方案|DP
- [DP] BZOJ1079: [SCOI2008]着色方案
- bzoj 1079: [SCOI2008]着色方案 DP
- BZOJ 1079 [SCOI2008]着色方案 - 花式DP
- BZOJ 1079: [SCOI2008]着色方案 DP
- bzoj1079: [SCOI2008]着色方案 dp
- BZOJ1079 [SCOI2008]着色方案 记忆化搜索DP 妙啊
- bzoj1079: [SCOI2008]着色方案(dp)
- [BZOJ]1079: [SCOI2008]着色方案
- AC日记——[SCOI2008] 着色方案 bzoj 1079
- 【记忆化搜索】bzoj1079 [SCOI2008]着色方案
- 【bzoj1079】[SCOI2008]着色方案
- bzoj 1079: [SCOI2008]着色方案【记忆化搜索】
- BZOJ1079: [SCOI2008]着色方案