zoukankan      html  css  js  c++  java
  • Sereja and Two Sequences CodeForces

    大意: 给定序列$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 '
    '
    #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
    ", ans);
    }
    
  • 相关阅读:
    git ignore 添加忽略文件
    python| 闭包函数及装饰器
    python | DRF 框架知识总览
    python | CHROME底层原理和HTTP协议
    python| css 背景图片虚化效果
    python | js 图片与base64互相转换
    python | Linux各目录及每个目录的详细介绍
    python | 解决Django+Vue前后端分离的跨域问题及关闭csrf验证
    python | Nginx负载均衡策略
    python | Linux 搭建Nginx+uWSGI+Django环境
  • 原文地址:https://www.cnblogs.com/uid001/p/10649347.html
Copyright © 2011-2022 走看看