Codeforces 766C:Mahmoud and a Message(DP)
题目链接:http://codeforces.com/problemset/problem/766/C
题意
有一个长度为n的字符串,第二行有26个数字,位置1~26对应为a~z的字母,数值表示该字母不能出现在长度超过该值的子串中。
- 求有多少种划分该字符串的方法
- 求该字符串划分成子串后最大的子串的长度
- 求该字符串划分成满足要求的子串需要至少划分多少次
AC代码
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
char ch[maxn];
int c[maxn];
int a[maxn];
int dp[4][maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n;
cin>>n;
cin>>ch;
for(int i=0;i<26;i++)
cin>>a[i];
for(int i=0;i<n;i++)
{
c[i]=ch[i]-'a';
}
dp[0][0]=1;//从位置0开始转移
for(int i=1;i<=n;i++)
{
int res=INT_MAX/2;
dp[1][i]=INT_MIN/2;
dp[2][i]=INT_MAX/2;
for(int j=i-1;j>=0;j--)
{
res=min(res,a[c[j]]);
if(res<i-j)
break;
dp[0][i]=(dp[0][i]%mod+dp[0][j]%mod)%mod;
dp[1][i]=max(dp[1][i],max(dp[1][j],i-j));
dp[2][i]=min(dp[2][i],dp[2][j]+1);
}
}
for(int i=0;i<3;i++)
cout<<dp[i][n]<<endl;
return 0;
}
Codeforces 766C:Mahmoud and a Message(DP)的更多相关文章
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Problem - 38E - Let's Go Rolling!(DP)
E. Let's Go Rolling! time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Ural 2072:Kirill the Gardener 3(DP)
http://acm.timus.ru/problem.aspx?space=1&num=2072 题意:有n朵花,每朵花有一个饥渴值.现在浇花,优先浇饥渴值小的(即从小到大浇),浇花需要耗费 ...
- Codeforces Round #260 (Div. 2)C. Boredom(dp)
C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- codeforces 766 C. Mahmoud and a Message(简单dp)
题目链接:http://codeforces.com/contest/766/problem/C 题意:给你一个长度为n的字符串,这个字符串只包含小写字母,然后让你把这个字符串进行分割,形成若干个小的 ...
- CodeForces - 660F:Bear and Bowling 4(DP+斜率优化)
Limak is an old brown bear. He often goes bowling with his friends. Today he feels really good and t ...
- Codeforces 777B:Game of Credit Cards(贪心)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- Codeforces Round #658 (Div. 2) D. Unmerge(dp)
题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后 ...
- codeforces #260 DIV 2 C题Boredom(DP)
题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...
随机推荐
- Easyui的datagrid的editor(行编辑器)如何扩展datetimebox类型
在easyui的datagrid扩展方法中添加这样的时间日期(datetimebox)代码块 放在 $.extend($.fn.datagrid.defaults.editors,{datetim ...
- HTML代码转换为JavaScript字符串
我有时在工作中用到字符串拼接基本上来自于此,链接 http://www.css88.com/tool/html2js/
- 一个非常适合IT团队的在线API文档、技术文档工具 (ShowDoc)
在逸橙呆了不到两年,开发时后端都有开发接口API,来到数库,好多后端开发和前端沟通是还是发doc文档,很不方便,我向cto反应,自己找到这个,老乡田雷(php,隔壁村的)也用过,可能某些原因选择其他的 ...
- [POJ3481]Double Queue
Problem 0 结束操作 1 K P 将一个数K以优先级P加入 2 取出优先级最高的那个数 3 取出优先级最低的那个数 Solution Splay模板题 Notice 是输出数而不是输出优先级. ...
- docker 部署 flask(三)高级编写及生成镜像,安装requirements.txt
简介: 上一篇,我写了如何使用别人的docker基础镜像,生成我们的docker镜像. 也就最基本的flask,没有别的库(包)支持.连数据库支持都没有. 也就让大家了解一下怎么生成镜像而已. 本篇介 ...
- java套接字(socket)实例
客户端socket 流程: 1.连接远程主机 2.发送数据 3.接收数据 4.关闭流与socket连接 实例: import java.io.*; import java.net.Socket; im ...
- python socket 网络编程selector用法 (实用)
Server端: import socketimport selectors class Server(object):def init(self,sel,sock):self.sel = selse ...
- python常见面试题(mark)
1.大数据的文件读取 ① 利用生成器generator ②迭代器进行迭代遍历:for line in file 2.迭代器和生成器的区别 1)迭代器是一个更抽象的概念,任何对象,如果它的类有next方 ...
- SQL-5查找所有员工的last_name和first_name以及对应部门编号dept_no,也包括展示没有分配具体部门的员工
输出描述: 题目描述 查找所有员工的last_name和first_name以及对应部门编号dept_no,也包括展示没有分配具体部门的员工CREATE TABLE `dept_emp` (`emp_ ...
- window.location.replace()与window.location.href()区别
有3个页面 a,b,c 如果当前页面是c页面,并且c页面是这样跳转过来的:a->b->c 1:b->c 是通过window.location.replace("..xx/c ...