1079: [SCOI2008]着色方案

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=1079

Description

有n个木块排成一行,从左到右依次编号为1~n。你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块。所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n。相邻两个木块涂相同色显得很难看,所以你希望统计任意两个相邻木块颜色不同的着色方案。
Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point.
If you and your opponent meet in the same position, you can try to
fight with your opponent to score one point. For the proposal of game
balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder:
As a player specializing in high speed movement, he/she tries to avoid
dogfighting while attempting to gain points by touching buoys.
Fighter:
As a player specializing in dogfighting, he/she always tries to fight
with the opponent to score points. Since a fighter is slower than a
speeder, it's difficult for him/her to score points by touching buoys
when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting.
Since Asuka is slower than Shion, she decides to fight with Shion for
only one time during the match. It is also assumed that if Asuka and
Shion touch the buoy in the same time, the point will be given to Asuka
and Asuka could also fight with Shion at the buoy. We assume that in
such scenario, the dogfighting must happen after the buoy is touched by
Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

Input

第一行为一个正整数k,第二行包含k个整数c1, c2, ... , ck。

Output

输出一个整数,即方案总数模1,000,000,007的结果。

Sample Input

3
1 2 3

Sample Output

10

HINT

题意

题解:

直接dp[a][b][c][d][e][f]表示上一个状态为f时,我可以涂1次的有a个,涂两次的有b个,涂三次的有c个,涂四次的有d个,涂五次的有e个的方案数

直接记忆化搜索转移就好了

代码

#include<iostream>
#include<stdio.h>
using namespace std;
int tmp[];
int dp[][][][][][];
int vis[][][][][][];
#define mod 1000000007
long long dfs(int a,int b,int c,int d,int e,int n){
if(vis[a][b][c][d][e][n])
return dp[a][b][c][d][e][n];
if(a+b+c+d+e==)
return dp[a][b][c][d][e][n]=;
long long ans=;
if(a)ans+=(a-(n==))*dfs(a-,b,c,d,e,);
if(b)ans+=(b-(n==))*dfs(a+,b-,c,d,e,);
if(c)ans+=(c-(n==))*dfs(a,b+,c-,d,e,);
if(d)ans+=(d-(n==))*dfs(a,b,c+,d-,e,);
if(e)ans+=(e-(n==))*dfs(a,b,c,d+,e-,);
vis[a][b][c][d][e][n]=;
ans%=mod;
return dp[a][b][c][d][e][n]=ans;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
int x;scanf("%d",&x);
tmp[x]++;
}
printf("%d\n",dfs(tmp[],tmp[],tmp[],tmp[],tmp[],));
}

BZOJ 1079: [SCOI2008]着色方案 记忆化搜索的更多相关文章

  1. SCOI2008着色方案(记忆化搜索)

    有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i 种颜色的油漆足够涂ci 个木块.所有油漆刚好足够涂满所有木块,即 c1+c2+...+ck=n.相邻两个木块涂相同色显得很难 ...

  2. BZOJ1079: [SCOI2008]着色方案 (记忆化搜索)

    题意:有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块. 所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木块涂相同色显得很 ...

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

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

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

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

  5. bzoj 1079: [SCOI2008]着色方案【记忆化搜索】

    本来打算把每个颜色剩下的压起来存map来记忆化,写一半发现自己zz了 考虑当前都能涂x次的油漆本质是一样的. 直接存五个变量分别是剩下12345个格子的油漆数,然后直接开数组把这个和步数存起来,记忆化 ...

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

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

  7. BZOJ 1079 [SCOI2008]着色方案

    http://www.lydsy.com/JudgeOnline/problem.php?id=1079 思路:如果把每种油漆看成一种状态,O(5^15)不行 DP[a][b][c][d][e][f] ...

  8. [BZOJ 1068] [SCOI2007] 压缩 【记忆化搜索】

    题目链接:BZOJ - 1068 题目分析 这种记忆化搜索(区间 DP) 之前就做过类似的,也是字符串压缩问题,不过这道题稍微复杂一些. 需要注意如果某一段是 S1S1 重复,那么可以变成 M + S ...

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

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

随机推荐

  1. ActionBarSherlock的学习笔记(一) -------------- ActionBarSherlock的简要介绍

    1. 介绍 ActionBarSherlock 是Android compatibility library 的一个扩展, 不知道什么原因 Android 兼容开发包没有包含ActionBar. 所以 ...

  2. jQuery 制作的Tab标签切换选项卡

    基于jQuery实现的一个选项卡效果,重点体现在HTML里没有内联事件处理程序,而是定义在js文件里,做到行为与结构的分离.在实际应用过程中,只要保证选项卡模块结构代码的完整性,就可以任意添加N个同类 ...

  3. HDU 1671 Phone List(POJ 3630)

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. java web 学习四(http协议)

    一.什么是HTTP协议 HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...

  5. 仿酷狗音乐播放器开发日志二十三 修复Option控件显示状态不全的bug(附源码)

    转载请说明原出处,谢谢~~ 整个仿酷狗工程的开发将近尾声,现在还差选项设置窗体的部分,显然在设置窗体里用的最多的就是OptionUI控件,我在写好大致的布局后去测试效果,发现Option控件的显示效果 ...

  6. flex 图片旋转(解决公转和自转问题)

    在Flex中图片的旋转是既有公转和自转的.这样在图片旋转的时候就有一定小麻烦: 为了更好地说明问题,先引入两个概念:“自转”和“公转”.想象一下,地球在绕着太阳公转的同时,它自己也在自转.Flash应 ...

  7. flash recovery area配置

    检查数据库是否开启闪回: SQL> select flashback_on from v$database; FLASHBACK_ON ----------------------------- ...

  8. 机器学习----分布问题(二元,多元变量分布,Beta,Dir)

    这涉及到数学的概率问题. 二元变量分布:          伯努利分布,就是0-1分布(比如一次抛硬币,正面朝上概率) 那么一次抛硬币的概率分布如下: 假设训练数据如下: 那么根据最大似然估计(MLE ...

  9. [转]SQL中char、varchar、nvarchar的区别

    char    char是定长的,也就是当你输入的字符小于你指定的数目时,char(8),你输入的字符小于8时,它会再后面补空值.当你输入的字符大于指定的数时,它会截取超出的字符.   nvarcha ...

  10. 第二百四十九天 how can I 坚持

    竟然让我跟着他们去旅游..泡温泉,滑雪..西北坡,不去白不去. 罗娜,你别把我拉黑啊.哎,不知道咋办. 晚上玩了四局LOL,全输了,伤心. 还有今天抢票没抢到. 该怎么破,12点半正好在吃饭啊. 睡觉 ...