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

这题关键是注意到$\frac{s}{e}$的范围比较小, 直接暴力dp即可..

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, m, s, e;
vector<int> g[N];
int dp[N], a[N]; int main() {
scanf("%d%d%d%d", &n, &m, &s, &e);
REP(i,1,n) scanf("%d", a+i);
REP(i,1,m) {
int t;
scanf("%d", &t);
g[t].pb(i);
}
memset(dp,0x3f,sizeof dp);
dp[0] = 0;
int ans = 0;
REP(i,1,n) PER(j,0,s/e) {
auto t = upper_bound(g[a[i]].begin(),g[a[i]].end(),dp[j]);
if (t==g[a[i]].end()) continue;
dp[j+1] = min(dp[j+1], *t);
if (dp[j+1]+i+e*(j+1)<=s) ans=max(ans,j+1);
}
printf("%d\n", ans);
}

Sereja and Two Sequences CodeForces - 425C (dp)的更多相关文章

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

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

  2. Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (bitmasks +dp )

    https://codeforces.com/contest/1330/problem/D 题目大意:给出一个限制 d 与模数 m ,求出可以构造出的满足条件的数组 a 的个数,需要满足以下条件:   ...

  3. Codeforces Round #243 (Div. 1)——Sereja and Two Sequences

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24798219 题目链接 题意:给两个长度分别 ...

  4. Two Melodies CodeForces - 813D (DP,技巧)

    https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...

  5. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  6. codeforces的dp专题

    1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...

  7. Codeforces 721C [dp][拓扑排序]

    /* 题意:给你一个有向无环图.给一个限定t. 问从1点到n点,在不超过t的情况下,最多可以拜访几个点. 保证至少有一条路时限不超过t. 思路: 1.由无后向性我们可以知道(取决于该图是一个DAG), ...

  8. CodeForces 607C (DP) Hard problem

    题目:这里 题意:给定n个字符串,每个字符串可以进行一项操作,就是将这个字符串交换,就是该字符串的第一个和最后一个交换,第二个和倒数第二个交换,以此类推,当然可以选择对于 该字符串进行或不进行这项操作 ...

  9. codeforces 425C

    题意:给定长度为n,m<=100000的范围在100000以内的数组a,b. 现在给定两种操作: 第一种是ai,bj相等,ai,bj之前的数全删掉,费用为e,收益为1 第二种是把剩下的全部删掉, ...

随机推荐

  1. fw-cloud-framework项目配置、启动问题

    1.config组件:其配置优先级高于每个注册到同一个中心的工程的本地配置,所以在统一以dev这个 profile启动各个项目时,去config中心中找-dev结尾的各个工程名命名的文件. confi ...

  2. swagger 基础入门

    目录 Swagger简介 4 安装 4 一. Node.js 安装 4 二. node中http-server安装 4 三. 下载swagger-editor 4 四. 启动 swagger-edit ...

  3. FileAttributes Enum

    https://docs.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=netframework-4.7.2 读取FileA ...

  4. (zhuan) Notes on Representation Learning

    this blog from: https://opendatascience.com/blog/notes-on-representation-learning-1/   Notes on Repr ...

  5. 【JS】js操作json object

    //将表单序列化成字符串 $.fn.serializeObject = function () { var obj = {}; var count = 0; $.each(this.serialize ...

  6. CAS 单点登录 移动端获取TGT、ST 已经移动端登录页面不进行跳转的设置

    一.设置移动客户端验证ST通过后,页面不进行302重定向跳转 修改web.xml <!--**************************************************** ...

  7. CAS Client集群环境的Session问题及解决方案 不能退出登录

    casclient源代码下载链接:https://github.com/apereo/java-cas-client cas官网链接:https://www.apereo.org/projects/c ...

  8. 复习ing

    记不住啊,我能有什么办法,只好一遍又一遍看

  9. 简易Samba服务器配置

    Samba的作用是在Linux和windows之间通过网络进行资源共享.下面是简单的一个文件共享例子: 1.安装samba.samba-client服务 yum install samba samba ...

  10. C# widget

    Invoke(Delegate)的用法: //例如,要实时update窗体.如果在另一个线程中update,那么可以直接update(可以不在新线程中):也可以在Delegate中给出upate,然后 ...