Description

有一个长度为 \(n\) 有正负权值的序列,你一开始有一个值,每次到一个权值就加上,最少需要删掉多少数值才能到序列末尾.\(n \leqslant 750,m \leqslant 2 \times 10^5\)

Sol

DP+二分.

发现这个东西有后效性,就是前面选不选会影响后面的决策,并且权值太大无法记录.

但是我们可以倒着做,因为后面的决策无法影响前面的决策.

\(f[i][j]\) 表示到 \(i\) 删掉 \(j\) 个至少需要的初始权值.

因为初始权值非负,所以不可能在中途中出现负数,要处理掉,然后就两个决策,删或不删,转移就很好写了.

统计答案的时候他有单调性,可以二分.

Code

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std; typedef long long LL;
const int N = 755; int n,m;
LL a[N],f[N][N],w[N]; inline LL in(LL x=0,char ch=getchar()){ while(ch>'9'||ch<'0') ch=getchar();
while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x; }
void work(LL x){
int l=0,r=n,mid;
while(l<=r){
mid=(l+r)>>1;
if(f[1][mid] <= x) r=mid-1;
else l=mid+1;
}printf("%d\n",l);
}
int main(){ scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) cin>>a[i]; memset(f,0x3f,sizeof(f));
f[n+1][0]=0LL;
for(int i=n;i;i--) for(int j=0;j<n-i+1;j++){
f[i][j]=min(f[i][j],max(0LL,f[i+1][j]-a[i]));
f[i][j+1]=min(f[i][j+1],f[i+1][j]);
} for(;m--;) work(in());
return 0;
}

  

Codeforces 727 F. Polycarp's problems的更多相关文章

  1. codeforces 659F F. Polycarp and Hay(并查集+bfs)

    题目链接: F. Polycarp and Hay time limit per test 4 seconds memory limit per test 512 megabytes input st ...

  2. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集 bfs

    F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Pol ...

  3. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集

    题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...

  4. Polycarp's problems

    Polycarp's problems time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. AtcoderGrandContest 005 F. Many Easy Problems

    $ >AtcoderGrandContest \space 005 F.  Many Easy Problems<$ 题目大意 : 有一棵大小为 \(n\) 的树,对于每一个 \(k \i ...

  7. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  8. Codeforces 835 F. Roads in the Kingdom

    \(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...

  9. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

随机推荐

  1. codeforces 712C C. Memory and De-Evolution(贪心)

    题目链接:http://codeforces.com/problemset/problem/712/C 题目大意: 给连个值x,y (3 ≤ y < x ≤ 100 000), x,y都为等边三 ...

  2. codeforces 712A. Memory and Crow

    题目链接:http://codeforces.com/problemset/problem/712/A 题目大意: 给你一个数字系列,求其满足条件的一个序列. 条件为: ai = bi - bi +  ...

  3. expect神器安装和使用

    安装: mdkir /data/tools cd /data/tools wget http://prdownloads.sourceforge.net/tcl/tcl8.5.19-src.tar.g ...

  4. (自用)专业排版套装:CTeX + TeXStudio

    \documentclass[UTF8,landscape]{ctexart}%UTF8,ctexart中文支持,landscape横向版面 \usepackage{tikz}%画图 \usepack ...

  5. vim tab 中设置title

    在.bashrc添加 export PROMPT_COMMAND='echo -ne "\033]0;your wanted title\007"'

  6. yii2 widget示例

    <?php namespace app\components; use yii\base\Widget; use yii\helpers\Html; class RctReplyWidget e ...

  7. gradle providedCompile 与compile区别

    Gradle compile: 如果你的jar包/依赖代码 在编译的时候需要依赖,在运行的时候也需要,那么就用compile例如 : compile 'org.springframework.boot ...

  8. Spring回调方法DisposableBean接口

    除了自定义的destroy-method.还可以实现DisposableBean接口,来回调bean销毁时候执行的方法,这个接口有一个destroy方法,生命周期是是destroy----bean销毁 ...

  9. VS2010webConfig配置

    1.连接SqlServer数据库 <connectionStrings> <add name="ConnectionStringName" connectionS ...

  10. 关于Windows下安装mongodb和加入Windows系统启动项

    .首先:在http://www.mongodb.org/downloads官网下载最新的win版本的mongodb下载包(我下载到d盘) .加压缩,修改文件夹名字为mongodb,建立放数据库文件夹w ...