当前位置:网站首页>[Luogu p1541] tortoise chess [DP]
[Luogu p1541] tortoise chess [DP]
2022-07-02 22:51:00 【Ayane.】
[NOIP2010 Improvement group ] Tortoise
Background
On Xiao Ming's birthday , Dad gave him a pair of tortoise chess as a gift .
Title Description
The board of tortoise is a line N N N Lattice , A fraction on each grid ( Non-negative integer ). Chessboard 1 Lattice is the only starting point , The first N N N The grid is the end , The game requires the player to control a tortoise piece from the starting point to the end .
In the tortoise game M M M A crawling card , Divide into 4 Different types ( M M M A card may not contain all of 4 4 4 Types of cards , See Example ), Each type of card is marked with 1 , 2 , 3 , 4 1,2,3,4 1,2,3,4 One of the four numbers , After using this kind of card , The tortoise pieces will crawl forward with the corresponding number of squares . In the game , Each time the player needs to select a crawling card from all the crawling cards that he has not used before , Control the number of squares that the tortoise moves forward , Each card can only be used once .
In the game , The tortoise chess piece automatically obtains the score of the starting grid , And in the subsequent crawls, every time you reach a grid , You get the corresponding fraction for that lattice . The final game score of the player is the sum of the scores of all the squares that the tortoise pieces have reached from the beginning to the end .
Obviously , Using different crawling cards in different order will make the final game score different , Xiao Ming wants to find a way to use cards in order to get the most points in the game .
Now? , Tell you the score of each grid on the chessboard and all the crawling cards , Can you tell Xiao Ming , How many points can he get at most ?
Input format
Separate two numbers in each line with a space .
The first 1 1 1 That's ok 2 2 2 A positive integer N , M N,M N,M, The number of chessboard squares and crawling cards respectively .
The first 2 2 2 That's ok N N N Nonnegative integers , a 1 , a 2 , … , a N a_1,a_2,…,a_N a1,a2,…,aN, among a i a_i ai It means chessboard No i i i Points on a grid .
The first 3 3 3 That's ok M M M It's an integer , b 1 , b 2 , … , b M b_1,b_2,…,b_M b1,b2,…,bM, Express M The numbers on a crawling card .
Input data to make sure it's just used up at the end M M M A crawling card .
Output format
1 1 1 It's an integer , It means the maximum score Xiao Ming can get .
Examples #1
The sample input #1
9 5
6 10 14 2 8 8 18 5 17
1 3 1 2 1
Sample output #1
73
Tips
Every test point 1 s 1s 1s
Xiao Ming uses crawling cards in the order of 1 , 1 , 3 , 1 , 2 1,1,3,1,2 1,1,3,1,2, The score is 6 + 10 + 14 + 8 + 18 + 17 = 73 6+10+14+8+18+17=73 6+10+14+8+18+17=73. Be careful , Because the starting point is 1 1 1, So automatically get the first 1 1 1 The fraction of a lattice 6 6 6.
about 30 % 30\% 30% Data are available. 1 ≤ N ≤ 30 , 1 ≤ M ≤ 12 1≤N≤30,1≤M≤12 1≤N≤30,1≤M≤12.
about 50 % 50\% 50% Data are available. 1 ≤ N ≤ 120 , 1 ≤ M ≤ 50 1≤N≤120,1≤M≤50 1≤N≤120,1≤M≤50, And 4 4 4 Sort of crawling cards , The number of cards of each type will not exceed 20 20 20.
about 100 % 100\% 100% Data are available. 1 ≤ N ≤ 350 , 1 ≤ M ≤ 120 1≤N≤350,1≤M≤120 1≤N≤350,1≤M≤120, And 4 4 4 Sort of crawling cards , The number of cards of each type will not exceed 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
analysis :
set up f i , j , k , l f_{i,j,k,l} fi,j,k,l Indicates that one step card is used i i i Time Two steps j j j And so on
Because there are only 40 40 40 Zhang therefore O ( n 4 ) O(n^4) O(n4) We can do
So direct transfer
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;
}
边栏推荐
- SimpleITK使用——4. 奇怪的问题
- Pointer array parameter passing, pointer parameter passing
- 【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
- 数学建模——图与网络模型及方法(一)
- 分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
- Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
- UE4 UI adaptive screen
- go 条件变量
- Regular expression (2)
- Notes on key vocabulary in the English original of the biography of jobs (11) [chapter nine]
猜你喜欢
NC50965 Largest Rectangle in a Histogram
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
Leetcode circular linked list (fast and slow pointer) code line by line interpretation
NC24325 [USACO 2012 Mar S]Flowerpot
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
大话云原生之负载均衡篇-小饭馆客流量变大了
Oracle-PL/SQL编程
手写ORM(对象关系映射)增删改查
地方经销商玩转社区团购模式,百万运营分享
随机推荐
杰理之样机无触摸,拆机之后重新安装变正常【篇】
Simpleitk use - 3 Common operations
[QT] QT multithreading development - reentrancy and thread safety
Pointer - function pointer
[QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
位的高阶运算
I admire that someone explained such an obscure subject as advanced mathematics so easily
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
傑理之修改不需要長按開機功能【篇】
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
世界环境日 | 周大福用心服务推动减碳环保
《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
杰理之样机在多次触摸后会触发关机【篇】
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
Build your own website (22)
UE4 game architecture learning notes
#include errors detected. Please update your includePath.
Methods of adding styles to native JS
Oracle-游标
Wait to solve the zombie process