题目链接:https://cn.vjudge.net/contest/281963#problem/E

题目大意:中文题目

具体思路:这个题脑洞有点大,因为ci的数据量非常小,所以我们可以根据这个来进行操作,我们要找的答案=使用1次的颜色方案数+使用2次的颜色的方案数+使用3次的颜色的方案数+.....。

具体的解释看代码:

 #include<iostream>
#include<stack>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
# define ll long long
const int mod = 1e9+;
const int maxn = +;
ll vis[];
ll dp[][][][][][];
ll dfs(ll t1,ll t2,ll t3,ll t4,ll t5,ll pre)
{
if(t1+t2+t3+t4+t5==)
return dp[t1][t2][t3][t4][t5][pre]=;
if(dp[t1][t2][t3][t4][t5][pre])
return dp[t1][t2][t3][t4][t5][pre];
ll ans=;
if(t1)
ans+=dfs(t1-,t2,t3,t4,t5,)*(t1-(pre==)),ans%=mod;// 减去为了返回原来的状态而多加的1
if(t2)
ans+=dfs(t1+,t2-,t3,t4,t5,)*(t2-(pre==)),ans%=mod;//t1+1的原因是:当t1存在的时候递归形式t1-1,为了恢复原来的状态,所以是t1+1,。
if(t3)
ans+=dfs(t1,t2+,t3-,t4,t5,)*(t3-(pre==)),ans%=mod;
if(t4)
ans+=dfs(t1,t2,t3+,t4-,t5,)*(t4-(pre==)),ans%=mod;
if(t5)
ans+=dfs(t1,t2,t3,t4+,t5-,)*t5,ans%=mod;
return dp[t1][t2][t3][t4][t5][pre]=ans;
}
int main()
{
int k;
scanf("%d",&k);
for(int i=; i<=k; i++)
{
int tmp;
scanf("%d",&tmp);
vis[tmp]++;
}
ll ans=dfs(vis[],vis[],vis[],vis[],vis[],);
printf("%lld\n",ans);
return ;
}

E - 着色方案 HYSBZ - 1079 (计数DP)的更多相关文章

  1. BZOJ 1079: [SCOI2008]着色方案(巧妙的dp)

    BZOJ 1079: [SCOI2008]着色方案(巧妙的dp) 题意:有\(n\)个木块排成一行,从左到右依次编号为\(1\)~\(n\).你有\(k\)种颜色的油漆,其中第\(i\)种颜色的油漆足 ...

  2. 2018.10.20 bzoj1079: [SCOI2008]着色方案(多维dp)

    传送门 dp妙题. f[a][b][c][d][e][last]f[a][b][c][d][e][last]f[a][b][c][d][e][last]表示还剩下aaa个可以用一次的,还剩下bbb个可 ...

  3. AC日记——[SCOI2008] 着色方案 bzoj 1079

    1079 思路: dp: 我们如果dp方程为15维,每维记录颜色还有多少种: 不仅tle,mle,它还re: 所以,我们压缩一下dp方程: 方程有6维,第i维记录有多少种颜色还剩下i次: 最后还要记录 ...

  4. 【BZOJ】1079: [SCOI2008]着色方案(dp+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1079 只能想到5^15的做法...........................果然我太弱. 其实 ...

  5. bzoj 1079: [SCOI2008]着色方案 DP

    1079: [SCOI2008]着色方案 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 803  Solved: 512[Submit][Status ...

  6. BZOJ 1079: [SCOI2008]着色方案 记忆化搜索

    1079: [SCOI2008]着色方案 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  7. [BZOJ 1079][SCOI 2008]着色方案

    1079: [SCOI2008]着色方案 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2237  Solved: 1361[Submit][Stat ...

  8. bzoj1079 着色方案 记忆化搜索(dp)

    题目传送门 题目大意: 有k种颜色,每个颜色ci可以涂个格子,要求相邻格子颜色不能一样,求方案数.ci<=5,k<=15. 思路: 题目里最重要的限制条件是相邻格子颜色不能相同,也就是当前 ...

  9. Bzoj 1079 着色方案 题解

    1079: [SCOI2008]着色方案 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2237  Solved: 1361[Submit][Stat ...

随机推荐

  1. 25 行 Python 代码实现人脸识别——OpenCV 技术教程

    OpenCV OpenCV 是最流行的计算机视觉库,原本用 C 和 C++ 开发,现在也支持 Python. 它使用机器学习算法在图像中搜索人的面部.对于人脸这么复杂的东西,并没有一个简单的检测能对是 ...

  2. android viewflipper的使用 实现图片滑动效果

    package com.homer.viewflipper; import android.app.Activity; import android.os.Bundle; import android ...

  3. 学习Spring Boot:(二十八)Spring Security 权限认证

    前言 主要实现 Spring Security 的安全认证,结合 RESTful API 的风格,使用无状态的环境. 主要实现是通过请求的 URL ,通过过滤器来做不同的授权策略操作,为该请求提供某个 ...

  4. 51nod1236 序列求和 V3 【数学】

    题目链接 51nod1236 题解 用特征方程求得斐波那契通项: \[f(n) = \frac{(\frac{1 + \sqrt{5}}{2})^{n} - (\frac{1 - \sqrt{5}}{ ...

  5. luogu1080 国王游戏(贪心+高精度)

    貌似这道题是碰巧蒙对了贪心的方式..就是把ai*bi越小的放在越前面 (不过也符合直觉) 然后统计答案需要用高精度,然后就调了一年 #include<cstdio> #include< ...

  6. rsync同步官方zabbix仓库搭建本地yum源

    1.同步资源 # rsync -vrt rsync://repo.zabbix.com/mirror/zabbix/3.4/rhel/7/x86_64/ /home/mirrors/zabbix/3. ...

  7. A1029. Median

    Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...

  8. A1101. Quick Sort

    There is a classical process named partition in the famous quick sort algorithm. In this process we ...

  9. 【洛谷P3586】LOG

    题目大意:维护一个集合,支持单点修改.查询小于 X 的数的个数.查询小于 X 的数的和. 题解:学习到了动态开点线段树.对于一棵未经离散化的权值线段树来说,对于静态开点来说,过大的值域会导致不能承受的 ...

  10. JAVA实现邮件发送功能(账号注册验证码、账号激活等)

    第一步,导入JAR包,JAR包下载地址[http://pan.baidu.com/s/1kVRvGyF] 如果是Maven,请直接在Pom文件中加入 <dependency> <gr ...