2018焦作网络赛B

dp维护一下最大值与最小值,注意边界情况的判定。

#include <iostream>
#include <cstring>

using namespace std;

const long long inf = (long long)1e18+(long long)9;
long long dp[7][1005];
long long dpx[7][1005];
int f[1005];
char s[15];

int main()
{
    int T;
//    int l;
    int n,m;
    long long k;
    long long ans;
    scanf("%d",&T);
    while(T--)
    {
        memset(dp,0,sizeof(dp));
        memset(dpx,0,sizeof(dpx));
        scanf("%d%d%lld",&n,&m,&k);
        for(int i=0;i<=m;i++)
        for(int j=0;j<=n;j++)
        {
            dp[i][j]=-inf;
            dpx[i][j]=inf;
        }
        for(int i=1;i<=n;i++)
        scanf("%d",&f[i]);
        getchar();
        scanf("%s",s);
        //for(int i=0;i<=m;i++)
        dpx[0][0]=dp[0][0]=k;
        ans=-inf;
        for(int i=1;i<=n;i++)
        {
            dpx[0][i]=dp[0][i]=k;
            for(int j = 0; j < m; j++)
            {
                dp[j+1][i]=-inf;
                dpx[j+1][i]=inf;
                if(j+1<=i-1)
                {
                    dp[j+1][i]=max(dp[j+1][i],dp[j+1][i-1]);
                    dpx[j+1][i]=min(dpx[j+1][i],dpx[j+1][i-1]);
                }
                //if(i<=j)continue;
                if(s[j]==‘+‘)
                {
                    dp[j+1][i]=max(dp[j+1][i],dp[j][i-1]+f[i]);
                    //dp[j+1][i]=max(dp[j+1][i],dpx[j][i-1]+f[i]);
                    //dpx[j+1][i]=min(dpx[j+1][i],dp[j][i-1]+f[i]);
                    dpx[j+1][i]=min(dpx[j+1][i],dpx[j][i-1]+f[i]);
                }
                if(s[j]==‘-‘)
                {
                    dp[j+1][i]=max(dp[j+1][i],dp[j][i-1]-f[i]);
                    //dp[j+1][i]=max(dp[j+1][i],dpx[j][i-1]-f[i]);
                    //dpx[j+1][i]=min(dpx[j+1][i],dp[j][i-1]-f[i]);
                    dpx[j+1][i]=min(dpx[j+1][i],dpx[j][i-1]-f[i]);
                }
                if(s[j]==‘*‘)
                {
                    dp[j+1][i]=max(dp[j+1][i],dp[j][i-1]*f[i]);
                    dp[j+1][i]=max(dp[j+1][i],dpx[j][i-1]*f[i]);
                    dpx[j+1][i]=min(dpx[j+1][i],dp[j][i-1]*f[i]);
                    dpx[j+1][i]=min(dpx[j+1][i],dpx[j][i-1]*f[i]);
                }
                if(s[j]==‘/‘&&f[i]!=0)
                {
                    dp[j+1][i]=max(dp[j+1][i],dp[j][i-1]/f[i]);
                    dp[j+1][i]=max(dp[j+1][i],dpx[j][i-1]/f[i]);
                    dpx[j+1][i]=min(dpx[j+1][i],dp[j][i-1]/f[i]);
                    dpx[j+1][i]=min(dpx[j+1][i],dpx[j][i-1]/f[i]);
                }
                if(j==m-1&&dp[j+1][i]>ans&&dp[j+1][i]!=inf&&j+1<=i)
                {
                    //cout<<i<<‘ ‘<<j<<‘ ‘<<dp[j+1][i]<<endl;
                    ans=dp[j+1][i];
                }
            }
        }
        if(ans==inf || ans==-inf)
        ans =k;
        //for()
        printf("%lld\n",ans);
    }
    return 0;
}
//0 1 2 3 4 5

原文地址:https://www.cnblogs.com/LMissher/p/9655101.html

时间: 2024-11-08 23:20:04

2018焦作网络赛B的相关文章

2018焦作网络赛E

区间更新加法与乘法,x取反是2^64-x-1,由于取模所以取反变成-x-1,就区间+1再*-1就可以了,最后区间询问求和. 待补 原文地址:https://www.cnblogs.com/LMissher/p/9655105.html

2018焦作网络赛 - Poor God Water 一道水题的教训

本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可重复同一种食物 2.每三格均不同食物时中间格子不可吃巧克力 3.每三格前后两格不可同时吃巧克力 以上三个条件的方案数,n<1e10 太长不看版:打表+快速幂AC 长篇吐槽版 很显然的,设\(dp[n][i][j][k]\),走到第\(n\)格时第\(n-2\)格的食物是\(i\),第\(n-1\)的食物

2018焦作网络赛J

不知道题意,队友用java大数+二分过了? import java.util.Arrays; import java.util.Scanner; import java.io.*; import java.math.*; public class Main { static boolean check(BigInteger num,BigInteger n) { boolean flag = true; BigInteger a = new BigInteger("0"); BigIn

2018焦作网络赛-E- Jiu Yuan Wants to Eat

题目描述 You ye Jiu yuan is the daughter of the Great GOD Emancipator.  And when she becomes an adult, she will be queen of Tusikur, so she wanted to travel the world while she was still young. In a country, she found a small pub called Whitehouse. Just

2018焦作网络赛G-Give Candies

G: Give Candies 时间限制: 1 Sec  内存限制: 128 MB 题目描述 There are N children in kindergarten. Miss Li bought them N candies.To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1…N),

2018焦作网络赛B-Mathematical Curse

B: Mathematical Curse 时间限制: 1 Sec  内存限制: 128 MB 题目描述 A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics when he was young, and was entangled in some mathematical curses. He studied hard until he reach

2018焦作网络赛 E Jiu Yuan Wants to Eat(线段树+树链剖分)

题意 对一个有1e5个点,点权初值为0的树上进行4种操作: 1.结点u到结点v上的所有点权乘x. 2.结点u到结点v上所有的点权加x. 3.结点u到结点v上所有的点权取非. 4.结点u到结点v路径上点权的和. 答案模\(2^{64}\) 思路 对操作1.2树链剖分加线段树维护即可,对操作3,取非操作为:一个二进制位上都为1 的数减去当前值,即:\(2^{64}-1-x\) , 由于答案模\(2^{64}\),通过点权用unsigned long long,只需维护\(-(x+1)\) 操作即可.

2018 CCPC网络赛

2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物品,问最终赚的钱的最大值. solution 用两个堆来维护,一个堆维护已经找到卖家的,一个堆维护还没找到卖家的. 对于第\(i\)个地点,在已经找到卖家的堆里找出卖的钱的最小值,如果最小值小于\(a_i\),则将卖家换成\(i\),然后将原来的卖家放到没找到卖家的那里:如果最小值对于\(a_i\)

2018徐州网络赛H. Ryuji doesn&#39;t want to study

题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1],a[2],a[3]...a[n] #include "bits/stdc++.h" using namespace std; #define ll long long const int MAXN=1e5+10; ll sum[MAXN],ans[MAXN]; ll num[MAXN];