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

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

【Codeforces 766 C Mahmoud and a Message】 + dp

2019-11-10 17:54:02
字體:
來源:轉載
供稿:網友

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
亚洲国产美女精品久久久久∴| 亚洲少妇中文在线| 欧美美最猛性xxxxxx| 另类专区欧美制服同性| 亚洲欧美一区二区激情| 欧美成人精品三级在线观看| 日韩欧美国产激情| 久久99亚洲热视| 成人午夜激情免费视频| 国产成人精品一区二区在线| 久久男人的天堂| 亚洲人成网站777色婷婷| 国产一区二区三区日韩欧美| 欧美极品在线播放| 91成人在线观看国产| 欧美国产一区二区三区| 久久伊人色综合| 国产成人精品久久久| 91精品视频一区| 亚洲精品福利在线观看| 亚洲精品免费在线视频| 91老司机精品视频| 欧美色欧美亚洲高清在线视频| 国产视频综合在线| 日韩精品中文字幕视频在线| 国产成人91久久精品| 欧美成人小视频| 亚洲福利在线看| 91精品国产成人| 日韩中文在线观看| 日av在线播放中文不卡| 粉嫩老牛aⅴ一区二区三区| 亚洲精品美女视频| 欧美最顶级的aⅴ艳星| 亚洲级视频在线观看免费1级| 日韩精品亚洲元码| 亚洲欧美日韩第一区| 亚洲激情在线观看视频免费| 欧美性猛交xxxx富婆| 亚洲国产欧美一区| xxxx性欧美| 97精品国产aⅴ7777| 欧美电影在线免费观看网站| 久久噜噜噜精品国产亚洲综合| 亚洲成人av中文字幕| 欧美日韩亚洲精品内裤| 中文字幕亚洲激情| 欧美日韩精品在线观看| 欧美黑人xxx| 久久精品免费播放| 一区二区欧美日韩视频| 日产精品久久久一区二区福利| 国产精品第一第二| 国产精品久久久久久久久久三级| 国产精品96久久久久久又黄又硬| 精品久久久久久久久久久久| 欧美洲成人男女午夜视频| 成人福利免费观看| 色综合男人天堂| 成人av在线天堂| 精品夜色国产国偷在线| 国产成人精品视频在线| 中文字幕久久亚洲| 欧美激情奇米色| 日韩久久精品成人| 91探花福利精品国产自产在线| 欧美中文在线观看国产| 在线播放精品一区二区三区| 成人黄色免费片| 九色成人免费视频| 91精品国产电影| 亚洲日本中文字幕免费在线不卡| 欧美性开放视频| 国产一区视频在线| 国内精品模特av私拍在线观看| 国产精品wwww| 中文字幕在线精品| 欧美成人午夜激情视频| www.亚洲一二| 国外成人在线直播| 国产精品久久久久影院日本| 久久久久久久久亚洲| 亚洲综合中文字幕在线观看| 亚洲综合在线中文字幕| 久久久久久国产精品| 久久99视频免费| 久久精品视频导航| 伊人一区二区三区久久精品| 欧美黄色片在线观看| 亚洲性日韩精品一区二区| 日韩精品在线免费观看| 国产精品影片在线观看| 亚洲欧美日韩中文视频| 欧美日韩美女视频| 亚洲成人黄色网| 国产精品久久一区主播| 国产91精品高潮白浆喷水| 成人激情电影一区二区| 亚洲直播在线一区| 亚洲视频日韩精品| 国产日韩精品综合网站| 这里只有视频精品| 亚洲一区二区福利| 亚洲综合在线小说| 精品久久久久久久久久久久久久| 亚洲自拍高清视频网站| 成人乱人伦精品视频在线观看| 国产精品久久久久久av| 最近中文字幕mv在线一区二区三区四区| 亚洲欧美另类中文字幕| 精品爽片免费看久久| 国产成人小视频在线观看| 日韩精品久久久久| 欧美性生交xxxxxdddd| 少妇高潮久久77777| 欧美激情免费在线| 日韩欧美在线播放| 欧美大尺度激情区在线播放| 久久九九国产精品怡红院| 亚洲а∨天堂久久精品喷水| 国产午夜精品理论片a级探花| 久久国产精品久久久久久| 国产一区视频在线| 久久99青青精品免费观看| 日韩精品中文字幕在线观看| 中文字幕亚洲无线码a| 欧美成人一区二区三区电影| 欧美激情一二区| 欧美专区国产专区| 91免费视频网站| 久久免费高清视频| 亚洲精品网站在线播放gif| 欧美性视频网站| 一区国产精品视频| 国产97色在线|日韩| 国产日本欧美在线观看| 麻豆乱码国产一区二区三区| 亚洲精品久久视频| 欧美一区二区色| 亚洲欧美在线免费观看| 成人精品网站在线观看| 一区二区三区视频免费| 欧美成人性色生活仑片| 国产亚洲a∨片在线观看| 北条麻妃99精品青青久久| 日本一欧美一欧美一亚洲视频| 国产日韩欧美另类| 深夜福利国产精品| 国产午夜精品理论片a级探花| 成人黄色网免费| 国产精品丝袜久久久久久不卡| 少妇av一区二区三区| 日韩在线视频网| 亚洲欧美一区二区三区在线| 日韩成人在线视频| 亚洲少妇中文在线| 亚洲欧洲在线视频| 欧美激情在线一区| 26uuu亚洲国产精品| 国产一区二区视频在线观看| 国产精品盗摄久久久| 欧美中文在线视频| 国产成人精品一区二区| 欧美精品18videos性欧美|