当前位置:网站首页>【洛谷P1541】乌龟棋【DP】
【洛谷P1541】乌龟棋【DP】
2022-07-02 22:07:00 【Ayane.】
[NOIP2010 提高组] 乌龟棋
题目背景
小明过生日的时候,爸爸送给他一副乌龟棋当作礼物。
题目描述
乌龟棋的棋盘是一行 N N N个格子,每个格子上一个分数(非负整数)。棋盘第1格是唯一的起点,第 N N N格是终点,游戏要求玩家控制一个乌龟棋子从起点出发走到终点。
乌龟棋中 M M M张爬行卡片,分成4种不同的类型( M M M张卡片中不一定包含所有 4 4 4种类型的卡片,见样例),每种类型的卡片上分别标有 1 , 2 , 3 , 4 1,2,3,4 1,2,3,4四个数字之一,表示使用这种卡片后,乌龟棋子将向前爬行相应的格子数。游戏中,玩家每次需要从所有的爬行卡片中选择一张之前没有使用过的爬行卡片,控制乌龟棋子前进相应的格子数,每张卡片只能使用一次。
游戏中,乌龟棋子自动获得起点格子的分数,并且在后续的爬行中每到达一个格子,就得到该格子相应的分数。玩家最终游戏得分就是乌龟棋子从起点到终点过程中到过的所有格子的分数总和。
很明显,用不同的爬行卡片使用顺序会使得最终游戏的得分不同,小明想要找到一种卡片使用顺序使得最终游戏得分最多。
现在,告诉你棋盘上每个格子的分数和所有的爬行卡片,你能告诉小明,他最多能得到多少分吗?
输入格式
每行中两个数之间用一个空格隔开。
第 1 1 1行 2 2 2个正整数 N , M N,M N,M,分别表示棋盘格子数和爬行卡片数。
第 2 2 2行 N N N个非负整数, a 1 , a 2 , … , a N a_1,a_2,…,a_N a1,a2,…,aN,其中 a i a_i ai表示棋盘第 i i i个格子上的分数。
第 3 3 3行 M M M个整数, b 1 , b 2 , … , b M b_1,b_2,…,b_M b1,b2,…,bM,表示M张爬行卡片上的数字。
输入数据保证到达终点时刚好用光 M M M张爬行卡片。
输出格式
1 1 1个整数,表示小明最多能得到的分数。
样例 #1
样例输入 #1
9 5
6 10 14 2 8 8 18 5 17
1 3 1 2 1
样例输出 #1
73
提示
每个测试点 1 s 1s 1s
小明使用爬行卡片顺序为 1 , 1 , 3 , 1 , 2 1,1,3,1,2 1,1,3,1,2,得到的分数为 6 + 10 + 14 + 8 + 18 + 17 = 73 6+10+14+8+18+17=73 6+10+14+8+18+17=73。注意,由于起点是 1 1 1,所以自动获得第 1 1 1格的分数 6 6 6。
对于 30 % 30\% 30%的数据有 1 ≤ N ≤ 30 , 1 ≤ M ≤ 12 1≤N≤30,1≤M≤12 1≤N≤30,1≤M≤12。
对于 50 % 50\% 50%的数据有 1 ≤ N ≤ 120 , 1 ≤ M ≤ 50 1≤N≤120,1≤M≤50 1≤N≤120,1≤M≤50,且 4 4 4种爬行卡片,每种卡片的张数不会超过 20 20 20。
对于 100 % 100\% 100%的数据有 1 ≤ N ≤ 350 , 1 ≤ M ≤ 120 1≤N≤350,1≤M≤120 1≤N≤350,1≤M≤120,且 4 4 4种爬行卡片,每种卡片的张数不会超过 40 40 40; 0 ≤ a i ≤ 100 , 1 ≤ i ≤ N , 1 ≤ b i ≤ 4 , 1 ≤ i ≤ M 0≤a_i≤100,1≤i≤N,1≤b_i≤4,1≤i≤M 0≤ai≤100,1≤i≤N,1≤bi≤4,1≤i≤M。
l i n k link link
分析:
设 f i , j , k , l f_{i,j,k,l} fi,j,k,l表示一步卡牌用了 i i i次 两步用了 j j j次以此类推
因为每种最多只有 40 40 40张 所以 O ( n 4 ) O(n^4) O(n4)可做
那么直接转移
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define reg register
using namespace std;
typedef long long ll;
const int N=355,M=45;
int n,m,val[N],f[M][M][M][M],a,b,c,d;
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&val[i]);
for(int i=1,x;i<=m;i++)
{
scanf("%d",&x);
if(x==1) a++;
if(x==2) b++;
if(x==3) c++;
if(x==4) d++;
}
f[0][0][0][0]=val[1];
for(int i=0;i<=a;i++)
for(int j=0;j<=b;j++)
for(int k=0;k<=c;k++)
for(int l=0;l<=d;l++)
{
int step=i+j*2+k*3+l*4+1;
if(i>0) f[i][j][k][l]=max(f[i][j][k][l],f[i-1][j][k][l]+val[step]);
if(j>0) f[i][j][k][l]=max(f[i][j][k][l],f[i][j-1][k][l]+val[step]);
if(k>0) f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k-1][l]+val[step]);
if(l>0) f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k][l-1]+val[step]);
}
printf("%d",f[a][b][c][d]);
return 0;
}
边栏推荐
- 解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
- New feature of go1.18: trylock, which has been tossed n times
- Oracle cursor
- Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
- Unity3d learning notes 4 - create mesh advanced interface
- 送给即将工作的自己
- Mathematical modeling -- graph and network models and methods (I)
- Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
- U++ 学习笔记 ----松弛
- PHP微信抢红包的算法
猜你喜欢

Struct, bit segment, enumeration, union

UE4 game architecture learning notes

SimpleITK使用——4. 奇怪的问题

It's not easy to say I love you | use the minimum web API to upload files (swagger support) # yyds dry inventory #

Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning

Pointer and string

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
![[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)](/img/07/6f2dfb543cb0ab4f27169da7e6ad07.jpg)
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)

Basic concepts of image and deep understanding of yuv/rgb

图形视图框架
随机推荐
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
[shutter] shutter resource file use (import resource pictures | use image resources)
#include errors detected. Please update your includePath.
Niuke: Dragon and dungeon games
Wait to solve the zombie process
[LeetCode] 存在重复元素【217】
NC50965 Largest Rectangle in a Histogram
服务器响应状态码
Pointer - function pointer
Market Research - current market situation and future development trend of high tibial osteotomy plate
[LeetCode] 回文数【9】
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
Storage unit conversion
Regular expression (2)
Oracle cursor
'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
电商系统微服务架构
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
杰理之直接触摸样机的顶针反应不正常【篇】