题目链接: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. Java并发编程(五)JVM指令重排

    我是不是学了一门假的java...... 引言:在Java中看似顺序的代码在JVM中,可能会出现编译器或者CPU对这些操作指令进行了重新排序:在特定情况下,指令重排将会给我们的程序带来不确定的结果.. ...

  2. CAD绘制室外台阶步骤5.4

    1.在CAD的平面上用PL命令绘制台阶,如图: 绘制好了之后.进入三维模型,“工具""移位”选择台阶,回车,"Z"回车,输入数值“-450”如图 2.输入命令“ ...

  3. JS 浮点型计算的精度问题 推荐的js 库 推荐的类库 Numeral.js 和 accounting.js

    推荐的类库 Numeral.js 和 accounting.js 文章来自 http://www.css88.com/archives/7324#more-7324

  4. urllib 获取页面或发送信息

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- #urllib提供了一系列用于操作URL的功能. #urllib的request模块可以非常方便地抓取UR ...

  5. DevExpress WinForms使用教程:新的CheckEdit样式

    [DevExpress WinForms v18.2下载] 在最开始CheckEdit控件有16种样式, 使用CheckStyle属性,开发人员可以选择其中一种样式.随着时间推移,与其他Windows ...

  6. DevExpress WinForms使用教程:WinForms Sunburst控件

    [DevExpress WinForms v18.2下载] DevExpress WinForms v18.2中包含了一个新的WinForms组件 - WinForms Sunburst,它旨在帮助开 ...

  7. java.lang.Runnable 源码分析

    子接口:RunnableFuture<V>, RunnableScheduledFuture<V> 实现类:AsyncBoxView.ChildState, ForkJoinW ...

  8. ios中xib文件的用法

    ZQRView文件: // // ZQRView.h // // // Created by zzqqrr on 17/8/20. // // #import <UIKit/UIKit.h> ...

  9. Eclipse远程调试Tomcat

    1.Linux服务器中在Tomcat的catalina.sh文件添加如下内容: CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,ad ...

  10. navicat下载安装和激活一分钟完成

    下载navicat安装包和注册机 下载地址:https://pan.baidu.com/s/1Nakfuv7Z__vLiY6sHNusNg      提取码:v4gz 安装navicat  软件 以管 ...