C. An impassioned circulation of affection-尺取法或者DP
来源:互联网 发布:知乎爱德华诺顿的长相 编辑:程序博客网 时间:2024/06/05 09:16
给定一个串,再给你一群字母s+数字m
问你可否改变m个数字,使连贯的s字母最长。
根本没思路。。。
看的大牛的代码,真是写的太好了
只是有一点卡主了,那就是我每次是取得最小的。。
应该取最大的,卡一定的长度,这个长度内需要k个字母来装填,使其从头到尾都是s字母。当然越长越好啊。
越长说明里面本来包含的s字母就越多。O(∩_∩)O哈哈~
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int dp[1503][30];int m;char a[1503];void solve(int k,char x){ int cnt=0; int z[1503]; z[0]=0; memset(z,0,sizeof(z)); for(int i=0;i<m;i++){ if(a[i]==x) cnt++; z[i+1]=i+1-cnt; } int ans=0;; for(int i=1;i<=m;i++){ int f=lower_bound(z,z+i+1,z[i]-k)-z; ans=max(ans,i-f); } dp[k][x-'a']=ans; printf("%d\n",ans);}int main(){ int n,c; char d; memset(dp,-1,sizeof(dp)); while(~scanf("%d",&m)) { cin>>a; cin>>n; for(int i=1;i<=n;i++){ cin>>c>>d; if(dp[c][d-'a']!=-1) printf("%d\n",dp[c][d-'a']); else solve(c,d); } } return 0;}
阅读全文
0 0
- C. An impassioned circulation of affection-尺取法或者DP
- 814/ C. An impassioned circulation of affection(尺取法或者DP)
- 尺取法--An impassioned circulation of affection
- 【Codeforces 814 C. An impassioned circulation of affection】+ 尺取法
- codeforces 814C An impassioned circulation of affection 尺取法或者预处理
- Codeforces-An impassioned circulation of affection (尺取法)
- codeforces 814C An impassioned circulation of affection(尺取法模板)
- Codeforces 814C An impassioned circulation of affection【Dp】
- Codeforces 814C An impassioned circulation of affection (dp)
- Codeforces 814C An impassioned circulation of affection(dp)
- 814C An impassioned circulation of affection
- C. An impassioned circulation of affection
- C. An impassioned circulation of affection
- codeforces C. An impassioned circulation of affection
- An impassioned circulation of affection
- Codeforces-An impassioned circulation of affection (动态规划/尺取法)
- codeforces 814C An impassioned circulation of affection
- coderforces--418 div2 C. An impassioned circulation of affection
- Bootstrap 3.3.7学习笔记12
- 基于opencv的视频传输
- qwb与二叉树
- Charles抓取http接口数据
- Activity页面之间数据传递
- C. An impassioned circulation of affection-尺取法或者DP
- 对象图
- Android界面间的相互传值
- 设计模式(Design Pattern)
- 【Netty基础】Netty的高性能及NIO的epoll空轮询bug
- Python 定制序列 实例
- 报错 The 'build' command is only supported from within a workspace.
- 唯快不破:Web 应用的 13 个优化步骤
- 实战from GBDT to Xgboost