HYSBZ 1079(着色方案)
来源:互联网 发布:python大数据视频教程 编辑:程序博客网 时间:2024/05/09 07:56
Dp 神奇的状态转移……
Program fd;const mo=1000000007;var n,i,j:longint; c,tot:array[1..15] of longint; f:array[0..15,0..15,0..15,0..15,0..15,0..15] of int64;function dfs(a1,a2,a3,a4,a5,last:longint):int64;var i,j:longint; ans,q:int64; a:array[1..5] of longint;begin if f[a1,a2,a3,a4,a5,last]>0 then exit(f[a1,a2,a3,a4,a5,last]); a[1]:=a1;a[2]:=a2;a[3]:=a3;a[4]:=a4;a[5]:=a5; ans:=0; for i:=1 to 5 do if (a[i]>0) then begin if (last=i+1) and (a[i]=1) then continue; // if (last=i+1) then dec(a[i]); dec(a[i]); if i>1 then inc(a[i-1]); q:=dfs(a[1],a[2],a[3],a[4],a[5],i); inc(a[i]); if i>1 then dec(a[i-1]); if last=i+1 then ans:=(ans+(a[i]-1)*q) mod mo else ans:=(ans+a[i]*q) mod mo; // if (last=i+1) then inc(a[i]); end; f[a1,a2,a3,a4,a5,last]:=ans; exit(ans);end;begin read(n); fillchar(tot,sizeof(tot),0); for i:=1 to n do begin read(c[i]); inc(tot[c[i]]); end; fillchar(f,sizeof(f),0); for i:=1 to n do f[0,0,0,0,0,i]:=1; writeln(dfs(tot[1],tot[2],tot[3],tot[4],tot[5],0));end.
- HYSBZ 1079(着色方案)
- BZOJ 1079-着色方案(DP)
- BZOJ 1079 着色方案 (状压dp)
- 1079: [SCOI2008]着色方案
- 1079: [SCOI2008]着色方案
- 1079: [SCOI2008]着色方案
- bzoj 1079 着色方案
- 1079: [SCOI2008]着色方案
- BZOJ 1079: [SCOI2008]着色方案
- [BZOJ 1079][SCOI2008]着色方案
- 【bzoj 1079】: [SCOI2008]着色方案
- bzoj 1079 [SCOI2008]着色方案
- bzoj 1079 [SCOI2008]着色方案
- BZOJ 1079 [SCOI2008] 着色方案
- 1079[bzoj]: [SCOI2008]着色方案
- BZOJ 1079 [SCOI2008]着色方案
- [bzoj 1079--SCOI2008]着色方案
- 1079: [SCOI2008]着色方案(dp之记忆化搜索)
- 放松心情,慢慢看~
- OS_X_Lion install xcode note
- C# 中的委托和事件
- Weblogic 简介
- 2012年8月24日学习笔记---程序员面试宝典--循环、递归和概率
- HYSBZ 1079(着色方案)
- spring事务管理二:spring事务抽象
- HDU 3746 Cyclic Nacklace(KMP求最小循环元)
- Oracle游标(一)显式游标
- AR9344中ethernet处理方式分析
- 推荐Bibus——可在windows和linux操作系统下用的一款堪比Endnote的软件!!
- Extjs 让CheckboxSelectionModel类型Ext.grid.GridPanel的某行不能选择
- NAPI处理方式分析
- LINUX C代码风格