日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2024/1/17 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BZOJ 1079: [SCOI2008]着色方案 记忆化搜索 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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。相鄰兩個木塊涂相同色顯得很難看,所以你希望統(tǒng)計(jì)任意兩個相鄰木塊顏色不同的著色方案。
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

第一行為一個正整數(shù)k,第二行包含k個整數(shù)c1, c2, ... , ck。

?

Output

輸出一個整數(shù),即方案總數(shù)模1,000,000,007的結(jié)果。

?

Sample Input

3
1 2 3

Sample Output

10

HINT

?

題意

?

題解:

直接dp[a][b][c][d][e][f]表示上一個狀態(tài)為f時,我可以涂1次的有a個,涂兩次的有b個,涂三次的有c個,涂四次的有d個,涂五次的有e個的方案數(shù)

直接記憶化搜索轉(zhuǎn)移就好了

代碼

?

#include<iostream> #include<stdio.h> using namespace std; int tmp[10]; int dp[16][16][16][16][16][7]; int vis[16][16][16][16][16][7]; #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==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<n;i++){int x;scanf("%d",&x);tmp[x]++;}printf("%d\n",dfs(tmp[1],tmp[2],tmp[3],tmp[4],tmp[5],0)); }

?

總結(jié)

以上是生活随笔為你收集整理的BZOJ 1079: [SCOI2008]着色方案 记忆化搜索的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。