codeforces 425C
题意:给定长度为n,m<=100000的范围在100000以内的数组a,b。
现在给定两种操作:
第一种是ai,bj相等,ai,bj之前的数全删掉,费用为e,收益为1
第二种是把剩下的全部删掉,花费为之前删除的数的个数,并且得到的之前的收益(也就是必须这一步,不然1的收益都无效)
思路:刚开始看错题意了。。以为第二种操作花费为剩下的个数。。
然后多写了一段。。。还wa了。。虽然思路差不多。。
那么题目等价与a,b数组中找到最多的不相交线段。。
但是单纯这样还是要跪。。注意到s/e<=300,那么就可以二维dp
f[i][j]表示做到a[i],有j对不相交线段的最近额b数组出现在什么位置。。
那么做法就很像不下降子序列nlogn版本的做法了。。
具体看代码吧。。
code:
#include <bits/stdc++.h>
using namespace std;
#define vii vector<int>::iterator
#define M0(a) memset(a, 0, sizeof(a))
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
int a[], b[], n, m, s, e;
int f[];
vector<int> p[]; void init(){
repf(i, , n) scanf("%d", &a[i]);
repf(i, , m) scanf("%d", &b[i]);
for (int i = ; i <= ; ++i) p[i].clear();
repf(i, , m) p[b[i]].push_back(i);
} void solve(){
int t = s / e;
// cout << t << endl;
for (int i = ; i <= t; ++i) f[i] = m+;
f[] = ;
int ans = ;
for (int i = ; i < n; ++i){
for (int j = t; j >= ; --j) if (f[j] <= m){
vii it = upper_bound(p[a[i+]].begin(), p[a[i+]].end(), f[j]);
if (it != p[a[i+]].end()) f[j+] = min(f[j+], *it);
}
for (int j = ; j <= t; ++j) if (f[j] <= m)
if (j * e + f[j] + i + <= s) ans = max(ans, j);
}
cout << ans << endl;
} int main(){
// freopen("a.in", "r", stdin);
while (scanf("%d%d%d%d", &n, &m, &s, &e) != EOF){
init();
solve();
}
}
codeforces 425C的更多相关文章
- codeforces 425C Sereja and Two Sequences(DP)
题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...
- Sereja and Two Sequences CodeForces - 425C (dp)
大意: 给定序列$a,b$, 每次可以任取两个相同大小的$a_i,b_j$删除$a_i,b_j$左侧所有元素, 花费为e, 得分1, 最后结束时必须再花费之前删除元素的个数, 不得分. 初始能量$s$ ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- iOS 关于僵尸对象和僵尸指针的那些事儿
引言 提到僵尸就感到一种恐怖,大家都知道“僵尸”是没有生命的,但是它确实是一种存在的类似生命体的一种生物.哈哈,当然本文的重点不是讨论“僵尸”,而是有关于ios当中经常遇到的僵尸指针(Zombie P ...
- windows 10启动盘制作工具
Rufus 官方网站:http://rufus.akeo.ie/
- 用asp.net c# HttpWebRequest获取网页源代码
public string GetPage(string url) { HttpWebRequest request = null; HttpWebResponse response = null; ...
- pdo文字水印类,验证码类,缩略图类,logo类
文字水印类 image.class.php <?php /** * webrx.cn qq:7031633 * @author webrx * @copyright copyright (c) ...
- 炫酷的时钟--canvas初体验
先啥也不说:来张效果图 我是根据:http://www.imooc.com/learn/133 这里的课程进行学习的.大大的感谢liuyubobobo老师的深入浅出的讲解!! 我在这里仅仅提供我自己的 ...
- 离线安装VS 2013开发工具的方法!
目前微软已正式发布了VS 2013的开发工具,但安装VS 2013开发工具前必须安装或升级到IE10,否则无法进行安装.本文主要介绍在Windows Server 2008 R2 SP1下离线安装IE ...
- hdu 1797 靠谱的算法应该是最大生成树,但是本人用最大流做的
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22294 Accepted: ...
- 企业内部从零开始安装docker hadoop 提纲
下载apache 项目 http://mirror.bit.edu.cn/apache/ 下载 centos 7 安装 盘 iso 大约7G 安装 centos7 copy 光盘盘中的 packag ...
- Appium学习路-打包apk和ipa篇
间隔这么长时间再去写Appium的学习篇是有原因的,因为在想要用appium测试ios时,发现appium只能测试debug版本的ipa包.然后就需要自己去学习打包了啊.然后就对xcode各种不了解, ...
- Java NIO教程 Selector
这次我们开讲非阻塞I/O中的Selector,它需要配合非阻塞的TCP和UDP来使用.首先我们先简单讲一下TCP和UDP的非阻塞通道. 非阻塞I/O通道 在上代码前我们先讲解一些最基本的知识.TCP和 ...