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

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

codeforces 766 C Mahmoud and a Message [基礎DP]【動態規劃】

2019-11-10 19:07:59
字體:
來源:轉載
供稿:網友

題目連接:http://codeforces.com/contest/766/PRoblem/C

———————————————————————–. C. Mahmoud and a Message time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard 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|b aa|b a|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. ———————————————————————–. 題目大意: 一個長度為n的僅含26小字母的字符串,要將其按要求分割成幾段,其中26種字母只能在長度為Ax的字串中,問你劃分的種類數是多少,字串的長度最長是多少,劃分出來的字符串個數最少是多少,

解題思路: 還是dp

對于子串中以第i個字符為止時,我們可以將其劃分到 ∈[i?Ai+1,i]的位置上,我們從這個位置向前尋找,一次次判斷就行了..

同時就能維護字串的最長長度了

字串的最少個數在一次次向前找中,維護最小值即可.

詳見代碼及注釋

附本題代碼 ———————————————————————–.

int a[30];int dp[3][1010];/**dp[0][i] 截止到第i個字符為止的劃分方案數 dp[1][i] 一個個的維護可劃分的最大長度 ,dp[2][i] 前一個的劃分點轉移到i,值+1, (劃分個數最少 自然是長度越長越好)*/string str;int main(){ int n; cin>>n; cin>>str; for(int i=0;i<26;i++) cin>>a[i]; dp[0][0] = 1; for(int i = 1; i <= n; ++i){ int len = INF; dp[1][i] = -INF; dp[2][i] = INF; for(int j = i - 1; j >= 0; --j){ len = min(len, a[str[j] - 'a']); if(len < i - j) break; //因為A_j有它的范圍 ,不能超過 dp[0][i] = (dp[0][i] + dp[0][j]) % MOD; //劃分方案數, dp[1][i] = max(dp[1][i], max(i - j, dp[1][j]));//就是維護最大值 dp[2][i] = min(dp[2][i], dp[2][j] + 1); //最少的劃分個數, } } cout << dp[0][n] << endl; cout << dp[1][n] << endl; cout << dp[2][n] << endl; return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
色妞欧美日韩在线| 欧美激情精品久久久久久黑人| 欧美专区国产专区| 国模精品系列视频| 亚洲韩国欧洲国产日产av| 欧美亚洲激情在线| 日韩精品欧美激情| 亚洲www永久成人夜色| 欧美中文字幕在线| 精品福利在线观看| 国产亚洲激情在线| 亚洲福利视频网站| 久久亚洲私人国产精品va| 欧美国产极速在线| 久久久噜久噜久久综合| 久久99视频免费| 亚洲精品欧美一区二区三区| 2019亚洲日韩新视频| 亚洲人成网站在线播| 色无极影院亚洲| 亚洲精选在线观看| 日韩av片免费在线观看| 日韩成人在线网站| 2019国产精品自在线拍国产不卡| 国产精品国产三级国产专播精品人| 久久久在线视频| 亚洲人成在线免费观看| 91天堂在线视频| 中文国产亚洲喷潮| 亚洲春色另类小说| 日韩亚洲欧美中文高清在线| 国内精品久久久久久久久| 伊人伊成久久人综合网小说| 欧美视频在线观看 亚洲欧| 国产精品96久久久久久又黄又硬| 中文字幕免费精品一区高清| 国产精品美女在线观看| 国产玖玖精品视频| 欧美成人免费小视频| 久久69精品久久久久久久电影好| 亚洲在线免费观看| 一本色道久久综合狠狠躁篇怎么玩| 亚洲欧美日韩国产中文| 久久艹在线视频| 欧美日韩成人在线观看| 久久九九有精品国产23| 久久视频精品在线| 亚洲福利视频免费观看| 8x海外华人永久免费日韩内陆视频| 在线观看日韩视频| 亚洲人成网站777色婷婷| 亚洲综合中文字幕68页| 国产成人综合av| 国产精品视频区| 国产精品91久久久久久| 国产精品夜色7777狼人| 夜夜躁日日躁狠狠久久88av| 久久久久免费精品国产| 亚洲欧洲国产精品| 欧美黑人性生活视频| 少妇高潮久久久久久潘金莲| 尤物九九久久国产精品的特点| 亚洲色图校园春色| 日韩电影免费观看中文字幕| 成人性生交大片免费看小说| 91欧美精品成人综合在线观看| 亚洲精品美女久久久| 97视频在线播放| www.亚洲免费视频| 久久国产精品亚洲| 91国自产精品中文字幕亚洲| 精品国产1区2区| 中文字幕精品国产| 欧美一级淫片aaaaaaa视频| 日韩免费观看av| 亚洲免费影视第一页| 国产免费久久av| 久久免费视频网| 成人国产精品色哟哟| 欧美亚洲在线视频| 欧美刺激性大交免费视频| 国产精品免费看久久久香蕉| 成人夜晚看av| 久久中文字幕一区| 欧美疯狂做受xxxx高潮| 57pao成人永久免费视频| 亚洲毛茸茸少妇高潮呻吟| 亚洲区一区二区| 国产99久久精品一区二区永久免费| 国模极品一区二区三区| 伊人成人开心激情综合网| 欧美极品美女视频网站在线观看免费| 青青草99啪国产免费| 热久久美女精品天天吊色| 亚洲成人教育av| 精品magnet| 欧美xxxx18国产| 日韩高清a**址| 国产精品旅馆在线| 久久偷看各类女兵18女厕嘘嘘| 久久久亚洲精品视频| 午夜精品久久久久久久99热| 日韩av在线播放资源| 久久视频这里只有精品| 欧美在线性爱视频| 亚洲精品美女在线观看播放| 色悠悠久久久久| 色老头一区二区三区在线观看| 国产精品99久久久久久久久| 久久中文字幕国产| 91av在线网站| 中文字幕在线亚洲| 亚洲精品久久久久久久久久久久久| 国产精品成人品| www.亚洲男人天堂| 色综合伊人色综合网| 狠狠爱在线视频一区| 91久久久精品| 久久69精品久久久久久久电影好| 欧美在线性视频| 欧美日韩性生活视频| 国产午夜精品全部视频播放| 久久免费高清视频| 日韩av不卡在线| 欧美大肥婆大肥bbbbb| 国产精品福利久久久| 欧美老女人性视频| 亚洲iv一区二区三区| 一区二区三区视频观看| 中文字幕在线亚洲| 日韩亚洲欧美中文高清在线| 欧美一区第一页| 日本精品视频在线播放| www国产91| 日产日韩在线亚洲欧美| 亚洲精品免费网站| 日韩欧美在线视频日韩欧美在线视频| 中文字幕亚洲字幕| 日本亚洲欧美成人| 日韩av成人在线观看| 欧美在线视频观看| 欧美激情精品久久久| 庆余年2免费日韩剧观看大牛| 8x拔播拔播x8国产精品| 在线观看精品国产视频| 国产精品高潮在线| 亚洲久久久久久久久久| 91精品国产99久久久久久| 亚洲女人天堂av| 久久久久久久久亚洲| 欧美剧在线观看| 不卡毛片在线看| 一区二区三区四区在线观看视频| 97视频在线观看视频免费视频| 国产区亚洲区欧美区| 国产亚洲欧洲高清| 国产精品国产三级国产专播精品人| 国产亚洲精品成人av久久ww| 久久久成人的性感天堂| 欧美三级欧美成人高清www| 久久久亚洲欧洲日产国码aⅴ| 成人国产精品久久久| 亚洲国产中文字幕在线观看| 国产精品亚洲第一区|