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. Java 组播

    MulticastSocketServer.java package cn.edu.buaa.multicast; import java.io.IOException; import java.ne ...

  2. PyCharm光标变粗的解决办法

    pycharm中光标变粗,如下: 此时变成了改写模式,只需要按下键盘的insert键即可

  3. 第一次使用Android Studio时你应该知道的一切配置

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  4. asp.net常用函数表

    文章转载于[IT花园]:http://www.itgarden.com.cn/showtopic-29.aspx Abs(number) 取得数值的绝对值. Asc(String) 取得字符串表达式的 ...

  5. Quartz.Net 基于XML配置启动

    1.App.config <configSections> <section name="quartz" type="System.Configurat ...

  6. nlssort函数的用法以及参数

    NLSSORT,可以用来进行语言排序,且不影响当前会话. 用法示例: 拼音SELECT * FROM TEAM ORDER BY NLSSORT(排序字段,'NLS_SORT = SCHINESE_P ...

  7. jQuery中的.bind()、.live()和.delegate()之间区别分析

    jQuery中的.bind()..live()和.delegate()之间区别分析,学习jquery的朋友可以参考下.   DOM树   首先,可视化一个HMTL文档的DOM树是很有帮助的.一个简单的 ...

  8. Android手机同步电脑端google chrome书签

    我先声明:文中FQ 都是博客园自动将中文(fan qiang)转换为FQ的,并不是我本来写的就是FQ~~ 手机和电脑都必须要能登录google(Xee:几乎所有做开发的人都每天的生活都离不开谷歌了,可 ...

  9. SqlServer 还原他服数据库只建立发布却删除不了

    本想做测试,从另一台服务器备份数据库还原到本机. 创建了一个发布,却删除不了,提示如下图: 参考论坛:http://bbs.csdn.net/topics/300046417 发现是数据库所有者问题, ...

  10. activti表结构

    1.结构设计 1.1.    逻辑结构设计 Activiti使用到的表都是ACT_开头的. ACT_RE_*: ’RE’表示repository(存储),RepositoryService接口所操作的 ...