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 ...
随机推荐
- 汉诺塔算法详解之C++
汉诺塔: 有三根杆子A,B,C.A杆上有N个(N>1)穿孔圆环,盘的尺寸由下到上依次变小.要求按下列规则将所有圆盘移至C杆: 每次只能移动一个圆盘: 大盘不能叠在小盘上面. 提示:可将圆盘临时置 ...
- jQuery实现抖动效果
//抖动效果 //intShakes:抖动次数:intDistance:抖动左右距离:intDuration:持续时间 jQuery.fn.shake = function (intShakes, i ...
- PIC32MZ tutorial -- Change Notification
In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...
- 跨域文件 clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8" ?> <access-policy> <cross-do ...
- ERROR SparkUncaughtExceptionHandler: Uncaught exception in thread
ERROR SparkUncaughtExceptionHandler: Uncaught exception in thread Thread[appclient-registration-retr ...
- 函数的定义和声明以及this
this = $(this)[0]; var person = { name : "lisa", age : "20", init : function(){ ...
- SQL SERVER 批量插入记录
--create function insertData(@count as int,@tsn as bigint,@id as int) --as --begin SET IDENTITY_INSE ...
- 提示框(UIAlertController)的使用。
添加出现在屏幕中间的提示框(也就是之前的UIAlertView): UIAlertController * av = [UIAlertController alertControllerWithTit ...
- shell和bat 监控进程,自动关机
1.linux 下监控进程,进程结束后关机 新建文件 monit.sh $chmod +x monit.sh 加入代码 #!/bin/sh a=; ]; do |;then echo "sh ...
- UI自动化测试的那些事
互联网产品的迭代速度远高于传统软件,尤其是移动APP不但更新频繁,还需要在不同硬件.系统版本的环境下进行大量兼容测试,这就给传统测试方法和测试工具带来了巨大挑战.为满足产品敏捷开发.快速迭代的需求,自 ...