当前位置:网站首页>[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;
}
边栏推荐
- 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
- Leetcode circular linked list (fast and slow pointer) code line by line interpretation
- 服务器响应状态码
- Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
- Perceptron model and Application
- go 条件变量
- Wait to solve the zombie process
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
- Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
- 杰理之样机无触摸,拆机之后重新安装变正常【篇】
猜你喜欢
![[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)](/img/2b/f31b81cedf37ca187bcaa20dfe0b83.png)
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)

Utilisation de simpletk - 4. Question étrange

Objects and object variables

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

Oracle-游标

UE4 game architecture learning notes

【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)

Graphic view frame

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
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
UE4 UI自适应屏幕
[LeetCode] 存在重复元素【217】
JS获取display为none的隐藏元素的宽度和高度的解决方案
U++ 学习笔记 堆
PMP项目整合管理
服务器响应状态码
[foreign journal] sleep and weight loss
Struct, bit segment, enumeration, union
Radis:Linux上安装Redis(步骤)
钟薛高回应产品1小时不化:含固体成分 融化不能变成水
图形视图框架
Oracle-PL/SQL编程
PHP optimizes SQL queries in foreach
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
[LeetCode] 数组中的第K个最大元素【215】
NC24325 [USACO 2012 Mar S]Flowerpot
Commodity information management system (C language document version)
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association