题目链接: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)的更多相关文章

  1. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 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 ...

  3. Ural 2072:Kirill the Gardener 3(DP)

    http://acm.timus.ru/problem.aspx?space=1&num=2072 题意:有n朵花,每朵花有一个饥渴值.现在浇花,优先浇饥渴值小的(即从小到大浇),浇花需要耗费 ...

  4. 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 ...

  5. codeforces 766 C. Mahmoud and a Message(简单dp)

    题目链接:http://codeforces.com/contest/766/problem/C 题意:给你一个长度为n的字符串,这个字符串只包含小写字母,然后让你把这个字符串进行分割,形成若干个小的 ...

  6. 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 ...

  7. Codeforces 777B:Game of Credit Cards(贪心)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  8. Codeforces Round #658 (Div. 2) D. Unmerge(dp)

    题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后 ...

  9. codeforces #260 DIV 2 C题Boredom(DP)

    题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...

随机推荐

  1. qt资源加载出错

    -1: error: No rule to make target '../InteractivePlayer/style.qss', needed by 'debug/qrc_res.cpp'.  ...

  2. mysql索引类型和方式

    索引 数据库的索引就像一本书的目录,能够加快数据库的查询速度. MYSQL索引有四种PRIMARY.INDEX.UNIQUE.FULLTEXT, 其中PRIMARY.INDEX.UNIQUE是一类,F ...

  3. Matlab、R向量与矩阵操作 z

    已有 1849 次阅读 2012-8-2 15:15 |系统分类:科研笔记|关键词:矩阵 480 window border center Matlab.R向量与矩阵操作   描    述 Matla ...

  4. POJ 2243 Knight Moves(BFS)

    POJ 2243 Knight Moves A friend of you is doing research on the Traveling Knight Problem (TKP) where ...

  5. 以黄门镇黄湾村某一扶贫文档为例——将Excel数据填入到已存在的Word模板

    傻瓜可以写出机器读得懂代码,但写出让人能读懂的代码的是优秀程序员 作用:通过Excel文件中的一列数据作为文件名创建Word文档,并将Excel中的一行数据填一表,实现自动化 Excel的VBA宏代码 ...

  6. minifilter

    暑假刚开始的时候,参照<寒江独钓>这本书,用VS2015写过的一个minifilter的框架,今天在博客上分享出来. VS2015已经有了minifilter的框架模板,直接生成了mini ...

  7. ui-router ng-router

    开发中常用ui-router来设置路由: ui-router使用很简单,延续了之前ngRoute的特点. 1.首先得注入ui.router模块. 接下来就是简单的配置 2.$stateProvider ...

  8. HDU - 2819 Swap(二分图最大匹配)

    Given an N*N matrix with each entry equal to 0 or 1. You can swap any two rows or any two columns. C ...

  9. PCP架构设计

    1.引言 现如今已经进入互联网时代,无论是工作还好娱乐都已经离不开互联网,与此同时,网络相关的问题也时不时的侵扰着我们,这需要我们具有一定网络相关知识来解决相关问题,而这时,一款工作便利,免费的网络分 ...

  10. 设置网页icon标志

    下载一个你喜欢的icon,文件格式为ico,然后将这个文件重命名为favicon.ico,并把文件放在网站的根目录下. 一般在ie8版本以上都支持icon图标.但是在此版本一下,我们需要添加一段代码. ...