ACM-ICPC 2018 焦作赛区网络预赛 B Mathematical Curse(DP)
https://nanti.jisuanke.com/t/31711
题意
m个符号必须按顺序全用,n个房间需顺序选择,有个初始值,问最后得到的值最大是多少。
分析
如果要求出最大解,维护最大值是不能得到的,因为有负数的参与,所以我们维护最大值和最小值。不管那么多,反正答案肯定是由极值产生的。
定义dp1[i][j]为用了i个符号,走了j间房后的最大值。因而dp2[][]就是对应的最小值。然后按要求转移。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f;
ll dp1[][],dp2[][];
int a[];
char f[];
int main(){
int n,m,k;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
scanf("%s",f+);
//puts(f+1);
memset(dp1,-inf,sizeof(dp1));
memset(dp2,inf,sizeof(dp2));
for(int j=;j<=n;j++) dp1[][j]=dp2[][j]=k;
for(int i=;i<=m;i++){
for(int j=i;j<=n;j++){
dp1[i][j]=dp1[i][j-];
dp2[i][j]=dp2[i][j-];
if(f[i]=='+'){
dp1[i][j]=max(dp1[i][j],dp1[i-][j-]+a[j]);
dp2[i][j]=min(dp2[i][j],dp2[i-][j-]+a[j]);
}else if(f[i]=='-'){
dp1[i][j]=max(dp1[i][j],dp1[i-][j-]-a[j]);
dp2[i][j]=min(dp2[i][j],dp2[i-][j-]-a[j]);
}else if(f[i]=='*'){
dp1[i][j]=max(dp1[i][j],dp1[i-][j-]*a[j]);
dp1[i][j]=max(dp1[i][j],dp2[i-][j-]*a[j]);
dp2[i][j]=min(dp2[i][j],dp2[i-][j-]*a[j]);
dp2[i][j]=min(dp2[i][j],dp1[i-][j-]*a[j]);
}else{
dp1[i][j]=max(dp1[i][j],dp1[i-][j-]/a[j]);
dp1[i][j]=max(dp1[i][j],dp2[i-][j-]/a[j]);
dp2[i][j]=min(dp2[i][j],dp2[i-][j-]/a[j]);
dp2[i][j]=min(dp2[i][j],dp1[i-][j-]/a[j]);
}
}
}
printf("%lld\n",dp1[m][n]);
}
return ;
}
ACM-ICPC 2018 焦作赛区网络预赛 B Mathematical Curse(DP)的更多相关文章
- ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)
There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...
- ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- ACM-ICPC 2018 焦作赛区网络预赛
这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...
- ACM-ICPC 2018 焦作赛区网络预赛J题 Participate in E-sports
Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...
- ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship
There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...
- ACM-ICPC 2018 焦作赛区网络预赛 L 题 Poor God Water
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- ACM-ICPC 2018 焦作赛区网络预赛 I题 Save the Room
Bob is a sorcerer. He lives in a cuboid room which has a length of AA, a width of BB and a height of ...
- ACM-ICPC 2018 焦作赛区网络预赛 H题 String and Times(SAM)
Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring won ...
- ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies
There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more inte ...
随机推荐
- Quartus prime16.0 组合逻辑always块中敏感向量表不全
前言 组合逻辑always块中向量敏感表不全导致的警告. 流程 1.对于如下代码块: always @(nstate /*or master_din or master_dout_reg*/) beg ...
- django 配置邮件发送 send_email
导入 send_email 所用方法导入 from django.core.mail import send_mail 因为使用的需要指明 发送人 所以要把 setting.py 中的 EMAIL_F ...
- Awesome-VR
Google-tool Marzipano是现代网络的360°媒体查看器.—— Google官网 文档 案例 源码 WebVR-Frameworks ReactVR - Build VR ...
- MT【289】含参绝对值的最大值之三
已知$a>0$,函数$f(x)=e^x+3ax^2-2e x-a+1$,(1)若$f(x)$在$[0,1]$上单调递减,求$a$的取值范围.(2)$|f(x)|\le1$对任意$x\in[0,1 ...
- 【CodeForces 730H】Delete Them
BUPT 2017 summer training (for 16) #1E 题意 找到匹配要删除的文件名们但不匹配其它文件名们的表达式.其中?匹配所有字符,其它字符匹配本身. 题解 如果某个位置出现 ...
- python学习日记(数据结构习题)
元素分类 有如下值li= [11,22,33,44,55,66,77,88,99,90],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中.即: {'k1' ...
- Square(斯特林反演)
题意 给出一个 \(n × m\) 大小的矩形,每个位置可以填上 \([1, c]\) 中的任意一个数,要求填好后任意两行互不等价且任意两列互不等价,两行或两列等价当且仅当对应位置完全相同,求方案数 ...
- 测试工作常用SQL查询语句
一.查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!>,!<,=>, ...
- PHP-FPM监控shell
!/bin/bash #监控的网页地址url="http://dev2.jwsmed.com" #fastcgi启动/重启/停止脚本路径PROG=/data/fistsoft/ph ...
- 51nod1079 poj2891 中国剩余定理与其扩展
题目链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1079 一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K. ...