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

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

【Codeforces 766 C Mahmoud and a Message】 + dp

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

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;}
上一篇:XML轉義字符

下一篇:可調鬧鐘的時鐘

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美性一区二区三区| 欧美成年人视频网站欧美| 91精品国产电影| 日韩欧美在线视频观看| 成人激情视频在线观看| 日本韩国欧美精品大片卡二| 欧美成人免费在线观看| 亚洲日韩中文字幕| 日韩成人激情影院| 久久久久久久久久久人体| 久久香蕉精品香蕉| 亚洲а∨天堂久久精品9966| 国产精品久久久久久久美男| 中文字幕在线观看亚洲| 91亚洲精品久久久久久久久久久久| 欧美日韩精品在线观看| 国产精品免费一区| 欧美高清性猛交| 亚洲美女在线观看| 亚洲天天在线日亚洲洲精| 日本乱人伦a精品| 成人欧美在线视频| 日韩毛片在线观看| 国产精品久久久999| 亚洲精品国产电影| 欧美日韩一区二区免费在线观看| 亚洲欧美日韩一区在线| 欧美电影免费观看高清完整| 欧美日韩福利在线观看| 久久久免费在线观看| 国产福利视频一区| 欧美整片在线观看| 欧美中文在线免费| 精品国产乱码久久久久久天美| 日日噜噜噜夜夜爽亚洲精品| 欧美寡妇偷汉性猛交| 亚洲女人天堂视频| 亚洲精品在线91| 日韩在线观看免费全集电视剧网站| 日本成人免费在线| 亚洲天堂开心观看| 日本免费一区二区三区视频观看| 青草青草久热精品视频在线网站| 成人国产精品av| 在线观看国产精品91| 日韩av电影在线网| 欧美日韩国产区| 97超碰国产精品女人人人爽| 55夜色66夜色国产精品视频| 国产成人精品日本亚洲| 欧美日韩国产黄| 国产成人精品在线观看| 日韩av电影国产| 日韩精品免费在线播放| 久久久国产精彩视频美女艺术照福利| 中文字幕免费国产精品| 亚洲视频精品在线| 久久综合伊人77777蜜臀| 18一19gay欧美视频网站| 亚洲奶大毛多的老太婆| 国产啪精品视频网站| 日韩久久精品成人| 亚洲第一网站男人都懂| 欧美性猛交xxxx黑人| 国产精品a久久久久久| 久久精品国产亚洲精品| 久久精品电影网站| 奇米4444一区二区三区| 亚洲第一区在线| 国产三级精品网站| 成人精品一区二区三区电影黑人| 久久精品久久久久电影| 久久久成人av| 欧美刺激性大交免费视频| 最新国产精品亚洲| 97视频在线播放| 亚洲国产古装精品网站| 亚洲第一网站免费视频| 亚洲最大成人在线| 亚洲新声在线观看| 日韩av黄色在线观看| 精品久久久久久久中文字幕| 国产精品入口免费视| 国产精品亚洲片夜色在线| 久久91精品国产91久久久| 国产精品久久久久秋霞鲁丝| 国产69精品99久久久久久宅男| 综合136福利视频在线| 久久人人看视频| 91最新国产视频| 亚洲va久久久噜噜噜久久天堂| 亚洲a区在线视频| 丝袜美腿亚洲一区二区| 欧美丝袜美女中出在线| 国产精品r级在线| 91精品国产91久久久久福利| 国产精品美女网站| 欧洲永久精品大片ww免费漫画| 在线日韩日本国产亚洲| 中文字幕日韩在线观看| 精品久久久av| 色偷偷av一区二区三区| 欧美激情一区二区三区在线视频观看| 亚洲石原莉奈一区二区在线观看| 欧美xxxx18国产| 91色精品视频在线| 国产91精品久| 日韩高清人体午夜| 91在线中文字幕| 精品国产视频在线| 亚洲成人久久久| 亚洲欧洲国产一区| www.欧美精品一二三区| 久久久久久中文字幕| 国产精品女人网站| 亚洲第一精品夜夜躁人人躁| 欧美性videos高清精品| 一区二区三区美女xx视频| 久久影视免费观看| 国产精品十八以下禁看| 国产一区二区丝袜高跟鞋图片| 精品久久久久久久久国产字幕| 亚洲国产欧美一区二区丝袜黑人| 久久五月天综合| 亚洲综合在线做性| 在线观看日韩欧美| 国产精品一区二区av影院萌芽| 午夜精品久久久久久久久久久久| 中文字幕亚洲一区| 国产精品美女呻吟| 日韩精品在线视频| 久久国产精品久久久久久久久久| 人人澡人人澡人人看欧美| 亚洲人高潮女人毛茸茸| 亚洲成人精品av| 国产精品丝袜白浆摸在线| 不用播放器成人网| 69影院欧美专区视频| 国产精品揄拍一区二区| 国产精品第一第二| 欧美午夜片欧美片在线观看| 欧美一级黄色网| 岛国av一区二区三区| 欧美激情中文字幕乱码免费| 国产精品日韩精品| 91国产美女在线观看| 欧美激情第三页| 91色精品视频在线| 亚洲视频axxx| 亚洲国产精彩中文乱码av| 久久精品99久久久久久久久| 国产成人一区二区三区电影| 欧洲成人免费aa| 亚洲精品黄网在线观看| 日韩在线视频二区| 自拍偷拍亚洲一区| 欧美电影免费观看高清完整| 精品网站999www| 亚洲精品综合久久中文字幕| 日本精品视频在线观看| 亚洲网站在线播放| 久久久久久国产精品美女| 在线观看国产精品淫| 色综合久久久久久中文网|