博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 1079: [SCOI2008]着色方案 记忆化搜索
阅读量:4350 次
发布时间:2019-06-07

本文共 3389 字,大约阅读时间需要 11 分钟。

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
#include
using namespace std;int tmp[10];int dp[16][16][16][16][16][7];int vis[16][16][16][16][16][7];#define mod 1000000007long 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==0) return dp[a][b][c][d][e][n]=1; long long ans=0; if(a)ans+=(a-(n==2))*dfs(a-1,b,c,d,e,1); if(b)ans+=(b-(n==3))*dfs(a+1,b-1,c,d,e,2); if(c)ans+=(c-(n==4))*dfs(a,b+1,c-1,d,e,3); if(d)ans+=(d-(n==5))*dfs(a,b,c+1,d-1,e,4); if(e)ans+=(e-(n==6))*dfs(a,b,c,d+1,e-1,5); vis[a][b][c][d][e][n]=1; ans%=mod; return dp[a][b][c][d][e][n]=ans; } int main(){ int n; scanf("%d",&n); for(int i=0;i

 

转载于:https://www.cnblogs.com/qscqesze/p/4941061.html

你可能感兴趣的文章
Ubuntu菜鸟入门(一)—— 截图工具安装
查看>>
List、Set、Map的区别
查看>>
php curl_init函数用法
查看>>
Leetcode-83 Remove Duplicates from Sorted List
查看>>
python之进程与线程
查看>>
python基础之数据类型(二)
查看>>
php中echo 与print 的区别
查看>>
将字符串的前后顺序翻转
查看>>
第13月第12天 Constraints priority
查看>>
CDH- cdh kafka已经卸载了,但是服务器还有kafka-topics这些命令可用,导致重新安装kafka出现问题...
查看>>
第9月第15天 设计模式 adapter mvc
查看>>
(转)Entity Framework - 利用T4 分离 Entity 和 DbContext
查看>>
IETESTER
查看>>
How To Learn English Very Fast
查看>>
多维表头的DataGridView
查看>>
github安装k8s
查看>>
c++之map函数/迭代器
查看>>
FFmpeg RTSP流通过UDP传输问题
查看>>
堆,二分,尺取
查看>>
Introduction to Rotary Cement Wet Kilns
查看>>