题意:给定长度为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的更多相关文章

  1. codeforces 425C Sereja and Two Sequences(DP)

    题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...

  2. Sereja and Two Sequences CodeForces - 425C (dp)

    大意: 给定序列$a,b$, 每次可以任取两个相同大小的$a_i,b_j$删除$a_i,b_j$左侧所有元素, 花费为e, 得分1, 最后结束时必须再花费之前删除元素的个数, 不得分. 初始能量$s$ ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. OKR——Objectives and Key Results

    1.OKR天生就有两个典型特征: 1)在精不在多——因为它是用来明确工作重心的(set one's priorities): 2)全体公开.透明——当你能够看到你的同级(peers).小老板(直接上级 ...

  2. 8.8 CSS知识点1

    什么是CSS CSS(Cascading Style Sheet) 层叠样式表 CSS3在CSS2的基础上增加了很多强大的新功能,目前主流浏览器都支持CSS3大部分功能.为了更好的向前兼容,不同的浏览 ...

  3. Operate blob data in Oracle via C#

    oracle table: CREATE TABLE "SCOTT"."TEST_BLOB"    (    "NAME" VARCHAR2 ...

  4. scala 学习心得

    scala 安装步骤 文件下载地址:www.scala-lang.org(Please report bugs at https://issues.scala-lang.org/. We welcom ...

  5. bind的用处

    刚做的项目,遇到过这样的问题,就是在动态追加标签时,给追加的标签添加事件时,在标签内追加不了,后来使用了delegate代理,能响应了,但也是不能给动态追加的代理 $("body" ...

  6. 使用虚拟机win7系统遇到问题及解决

    安装VMware并在其中安装win7专业版系统,这里不再赘述.因为...我就是照着百度来的.哈哈 说说使用中遇到的问题. 本来安装成功后,可以很愉快的运行着.后来莫名奇妙的出现了两个问题:1.虚拟机运 ...

  7. jQuery.bind() 函数详解

    bind()函数用于为每个匹配元素的一个或多个事件绑定事件处理函数. 此外,你还可以额外传递给事件处理函数一些所需的数据. 执行bind()时,事件处理函数会绑定到每个匹配元素上.因此你使用bind( ...

  8. [转载] Genymotion 解决虚拟镜像下载速度特别慢的问题

    本文转载自: http://blog.csdn.net/qing666888/article/details/51622762 Genymotion号称Android模拟器中运行最快的,但是服务器在国 ...

  9. iOS /* */多个嵌套解决

    解决办法 #if 0 /* */ #endif

  10. Python_sklearn机器学习库学习笔记(一)_一元回归

    一.引入相关库 %matplotlib inline import matplotlib.pyplot as plt from matplotlib.font_manager import FontP ...