【dp】P1541 乌龟棋
2024-10-21 23:04:39
链接:
https://www.luogu.org/problemnew/show/P1541
【思路】:
用f[a][b][c][d]表示,第一张卡用a张,第二张卡用b张..........然后就盘就ok了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<cstring>
using namespace std;
const int maxn=;
const int minn=-;
inline int read() {
char c = getchar();
int x = , f = ;
while(c < '' || c > '') {
if(c == '-') f = -;
c = getchar();
}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int n,m,a[],f[][][][],s[],js[],b;
int main() {
cin>>n>>m;
for(int i=; i<=n; ++i) {
a[i]=read();
}
for(int i=; i<=m; ++i) {
cin>>b;
js[b]++;
}
f[][][][]=a[];
for(int i=; i<=js[]; ++i) {
for(int j=; j<=js[]; ++j) {
for(int k=; k<=js[]; ++k) {
for(int l=; l<=js[]; ++l) {
int place=+i*+j*+k*+l*;
if(i!=) {
f[i][j][k][l]=max(f[i][j][k][l],f[i-][j][k][l]+a[place]);
}
if(j!=) {
f[i][j][k][l]=max(f[i][j][k][l],f[i][j-][k][l]+a[place]);
}
if(k!=) {
f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k-][l]+a[place]);
}
if(l!=) {
f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k][l-]+a[place]);
}
}
}
}
}
cout<<f[js[]][js[]][js[]][js[]];
return ;
}
最新文章
- 解决TalbleView头部或底部子控件不显示问题
- PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明
- 刀哥多线程Barrier异步gcd-08-barrier_async
- 简单易用的AOP/IOC框架
- jQuery 源码分析4: jQuery.extend
- windows下删除服务的方法
- 宣布发布 Windows Azure ExpressRoute,宣告与 Level 3 建立全新的合作伙伴关系并推出关于其他 Azure 服务令人振奋的更新
- debian6 更新python版本到python3.3
- 转:web_url函数学习
- Spring之Core模块
- YSLOW(一款实用的网站性能检测工具)
- Confluence 6 开始编辑 CSS
- PHP 二位数组按照下标排序
- PHP 扩展 MongoDB
- 洛谷P1074 靶形数独【dfs】【剪枝】
- SSM事务——事务回滚如何拿到返回值
- laravel 批量更新
- Centos crontab定时任务
- utime修改文件的存取,修改时间
- elastic search报错——“failed to obtain node locks”