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 & ...
随机推荐
- js中对象如何添加新属性?
假如登陆需要用户.密码.是否记住密码,那么怎么定义一个对象保存这些信息 1)方法1:声明动态对象 添加属性 //创建obj对象 var obj = new Object(); //为对象添加动态属性 ...
- BeanUtils.copyProperties(A,B)使用注意事项
***最近项目中用到BeanUtils.copyProperties(),然后踩了一些坑,也在网上查看了很多同行的测试和总结,现在将自己的测试.整理的注意事项分享如下,希望大家一起学习进步. ***注 ...
- JS 控制只能输入数字并且最多允许两位小数点
<html lang="en"> <head> <meta charset="UTF-8"> <title>JS ...
- LY.JAVA.DAY12.String类
2018-07-24 14:06:03 String类概述 字符串是由多个字符组成一串数据(字符序列) 字符串可以看成字符数组 一旦被赋值就不能被改变 值不能变 1.过程概述: 方法区---字符 ...
- django搭建博客
https://andrew-liu.gitbooks.io/django-blog/content/index.html
- Python Django 之 登录页面
一.创建project与app 1.创建project与app django-admin startproject mysite_login python manage.py startapp log ...
- 关于执行findbugs,checkstyle,jacoco插件检测代码,GitHook的脚本编写
Git钩子的作用: (pre-commit ) 在用户执行 git commit -m "xxx" 命令之前,先执行pre-commit文件中的脚本命令 在pre-commit文件 ...
- 关于iOS设备的那些事
首先推荐一个在用的库XYQuick 地址:https://github.com/uxyheaven/XYQuick idfa: 获取方式 [ASIdentifierManager sharedMana ...
- 学react的第一天
属性 class = className for = htmlFrom jsx语法被编译了,所以可以在return里写html标签 react的属性 constructor(props){ super ...
- jdk8-Optional类
概念: package com.atguigu.java8; import java.util.Optional; import org.junit.Test; /* * 一.Optional 容器类 ...