亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

【Codeforces 766 C Mahmoud and a Message】 + dp

2019-11-10 18:37:04
字體:
來源:轉載
供稿:網友

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Mahmoud wrote a message s of length n. He wants to send it as a birthday PResent to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That’s because this magical paper doesn’t allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1?=?2 he can’t write character ‘a’ on this paper in a string of length 3 or more. String “aa” is allowed while string “aaa” is not.

Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn’t overlap. For example, if a1?=?2 and he wants to send string “aaa”, he can split it into “a” and “aa” and use 2 magical papers, or into “a”, “a” and “a” and use 3 magical papers. He can’t split it into “aa” and “aa” because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.

A substring of string s is a string that consists of some consecutive characters from string s, strings “ab”, “abc” and “b” are substrings of string “abc”, while strings “acb” and “ac” are not. Any string is a substring of itself.

While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:

How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109?+?7.What is the maximum length of a substring that can appear in some valid splitting?What is the minimum number of substrings the message can be spit in?

Two ways are considered different, if the sets of split positions differ. For example, splitting “aa|a” and “a|aa” are considered different splittings of message “aaa”. Input

The first line contains an integer n (1?≤?n?≤?103) denoting the length of the message.

The second line contains the message s of length n that consists of lowercase English letters.

The third line contains 26 integers a1,?a2,?…,?a26 (1?≤?ax?≤?103) — the maximum lengths of substring each letter can appear in. Output

Print three lines.

In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109??+??7.

In the second line print the length of the longest substring over all the ways.

In the third line print the minimum number of substrings over all the ways. Examples Input

3 aab 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output

3 2 2

Input

10 abcdeabcde 5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output

401 4 3

Note

In the first example the three ways to split the message are:

a|a|baa|ba|ab

The longest substrings are “aa” and “ab” of length 2.

The minimum number of substrings is 2 in “a|ab” or “aa|b”.

Notice that “aab” is not a possible splitting because the letter ‘a’ appears in a substring of length 3, while a1?=?2.

最小長度dpm[i] = min(dp[i],dp[i - j] + 1),總數dpn[i] = (dp[i] + dp[i - j]) % mod,當前的個數,加上可以由j長度構成,i - j 依然合法的總數,最大長度每次更新;

AC代碼:

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int K = 1e3 + 10;const LL mod = 1e9 + 7;const LL KK = ((LL)1 << 63) - 1;const int INF = 0x3f3f3f3f;LL num[26],dpn[K],dpm[K];char s[K];bool bc(int a,int b){ int nl = b - a + 1; for(int i = a; i <= b; i++) if(num[s[i] - 'a'] < nl) return false; return true;}int main(){ printf("%lld/n",KK); LL N,ans = 0; scanf("%lld %s",&N,s + 1); for(int i = 0 ; i < 26; i++) scanf("%d",&num[i]); dpn[0] = 1,dpm[0] = 0; fill(dpm + 1,dpm + 1 + N,INF); for(LL i = 1; i <= N ; i++) for(LL j = 1 ; j <= i ; j++) if(bc(i - j + 1,i)){ dpn[i] = (dpn[i] + dpn[i - j]) % mod; dpm[i] = min(dpm[i],dpm[i - j] + 1); if(dpn[i]) ans = max(ans,j); } printf("%lld/n%lld/n%lld/n",dpn[N],ans,dpm[N]); return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产原创欧美精品| 在线a欧美视频| 亚洲免费人成在线视频观看| 亚洲无限乱码一二三四麻| 久久精品国产一区二区电影| 欧美日韩国产精品一区二区三区四区| 久久人人爽人人爽人人片av高请| 日韩av综合中文字幕| 久久影视电视剧免费网站清宫辞电视| 国产精品久久久久久久久久久久久久| 精品国产福利在线| 久久伊人免费视频| 日韩中文字幕在线| 欧美高清第一页| 久久久国产精品免费| 欧美一区二粉嫩精品国产一线天| 91丨九色丨国产在线| 日韩欧美有码在线| 欧美日韩性视频在线| 奇门遁甲1982国语版免费观看高清| 国产精品视频成人| 九九热99久久久国产盗摄| 欧美亚洲国产另类| 97视频免费观看| 国产精品久久久久久亚洲调教| 亚洲欧美国产精品专区久久| 最新国产成人av网站网址麻豆| 久久99久久亚洲国产| 欧美大片欧美激情性色a∨久久| 国产黑人绿帽在线第一区| 久久亚洲精品网站| 色中色综合影院手机版在线观看| 日韩av成人在线| 色yeye香蕉凹凸一区二区av| 97在线视频国产| 欧美在线精品免播放器视频| 8090理伦午夜在线电影| 欧美日韩一区二区在线| 日韩成人中文字幕在线观看| 欧美激情一区二区三区高清视频| 亚洲男人第一网站| 欧美黄色免费网站| 中文字幕欧美精品日韩中文字幕| 97国产一区二区精品久久呦| 久久久久久美女| 黄色精品在线看| 国产精品九九久久久久久久| 91色在线视频| 欧美壮男野外gaytube| 亚洲国产成人一区| 在线视频欧美性高潮| 国产精品18久久久久久首页狼| 国内精品久久久久久中文字幕| 国产精品亚洲视频在线观看| 国产精品九九九| 成人信息集中地欧美| 自拍偷拍亚洲欧美| 欧美午夜精品久久久久久久| 国产精品久久久久久av福利软件| 日韩在线观看网站| 亚洲最大福利网站| 日韩欧美中文第一页| 欧美高清在线观看| 久久男人av资源网站| 国产欧美亚洲精品| 亚洲成人久久久| 久久精品91久久久久久再现| 国产成人精品免费久久久久| 亚洲va欧美va国产综合久久| 久久综合国产精品台湾中文娱乐网| 在线看片第一页欧美| 久久精品小视频| 国产精品入口尤物| 91免费高清视频| 欧美激情视频一区二区| 亚洲欧洲av一区二区| 国产一区二区日韩精品欧美精品| 亚洲视频在线播放| 色黄久久久久久| 亚洲精品97久久| 欧美劲爆第一页| 成人免费网视频| 97国产在线视频| 伊人伊成久久人综合网小说| 国产成人aa精品一区在线播放| 亚洲国内精品视频| 伊人一区二区三区久久精品| 91免费国产网站| 在线成人激情视频| 日韩亚洲欧美成人| 日韩电视剧免费观看网站| 日本久久久a级免费| 欧美成人在线免费| 国内外成人免费激情在线视频网站| 亚洲国产精品va在线看黑人动漫| 久久久久久国产精品美女| 久久精品中文字幕电影| 国产精品视频在线观看| 欧美一级片久久久久久久| 国产日韩在线亚洲字幕中文| 色青青草原桃花久久综合| 2019日本中文字幕| 国产精品海角社区在线观看| 超碰97人人做人人爱少妇| 亚洲国产天堂久久综合网| 欧美激情精品久久久久久大尺度| 欧美成人免费在线视频| 久久久久国色av免费观看性色| 国模视频一区二区| 91天堂在线视频| 免费97视频在线精品国自产拍| 亚洲福利在线观看| 精品久久久久久中文字幕一区奶水| 91久久精品国产91性色| 992tv成人免费影院| 欧美黑人巨大xxx极品| 日韩av电影中文字幕| 91在线视频精品| 亚洲精品日韩激情在线电影| 成人免费午夜电影| 狠狠综合久久av一区二区小说| 川上优av一区二区线观看| 久久精品国产一区| 欧美精品一区三区| 欧美性在线观看| 欧美影院久久久| 青青草精品毛片| 精品激情国产视频| 欧美日韩中文字幕综合视频| 欧美国产日韩精品| 91精品国产91久久久久久不卡| 欧美一级视频在线观看| 欧美激情18p| 欧美尺度大的性做爰视频| 57pao成人国产永久免费| 亚洲国产精品yw在线观看| 欧美精品在线视频观看| 日韩免费高清在线观看| 亚洲国产精品成人av| 欧美大片在线看免费观看| 红桃视频成人在线观看| 91美女片黄在线观看游戏| 欧美日韩另类在线| 国产精品极品美女粉嫩高清在线| 欧美国产日韩一区二区| 欧美综合激情网| 北条麻妃一区二区在线观看| 91在线免费观看网站| 日韩在线视频导航| 久久久久久久影视| 一个人看的www欧美| 91爱视频在线| 亚洲色图35p| 国产精品27p| 精品久久久久久亚洲国产300| 欧美国产日韩免费| 亚洲国产精久久久久久久| 亚洲精品影视在线观看| 欧美精品日韩三级| 欧美午夜片欧美片在线观看| 亚洲一区制服诱惑| 日韩亚洲第一页| 久久久久久有精品国产| 国产网站欧美日韩免费精品在线观看|