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

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

【Codeforces 766 C Mahmoud and a Message】 + dp

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

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
国产精品久久久久久久久影视| 国产午夜精品全部视频播放| 亚洲第一偷拍网| 亚洲free嫩bbb| 国产欧美亚洲视频| 91成人在线视频| 激情亚洲一区二区三区四区| 成人免费直播live| 日韩精品中文字幕有码专区| 国产成人精品视频在线观看| 亚洲国产精品va在看黑人| 成人黄色在线观看| 亚洲精品一区在线观看香蕉| 欧美激情一级精品国产| 欧美成人精品在线| 97久久精品在线| 高清视频欧美一级| 亚洲精品小视频在线观看| 一色桃子一区二区| 国产精品成人av性教育| 精品中文字幕乱| 在线看欧美日韩| 国产精品日韩在线| 亚洲欧美中文日韩在线v日本| 欧美极品美女视频网站在线观看免费| 亚洲综合第一页| 韩国欧美亚洲国产| 91成人福利在线| www.亚洲人.com| 国产精品h片在线播放| 国内精品国产三级国产在线专| 国产精品日韩久久久久| 伊是香蕉大人久久| 国产亚洲免费的视频看| 国产精品爽黄69天堂a| 久久视频在线看| 欧美激情一区二区久久久| 亚洲色图欧美制服丝袜另类第一页| 欧美专区福利在线| 日韩在线精品视频| 久久久99久久精品女同性| 亚洲视频专区在线| 亚洲国产精品999| 在线亚洲欧美视频| 久久91超碰青草是什么| 91av在线视频观看| 国产精品久久久久久av下载红粉| 日韩视频在线一区| 午夜精品三级视频福利| 国产大片精品免费永久看nba| 日韩在线视频免费观看高清中文| 97激碰免费视频| 日韩欧美高清视频| 国产日韩欧美成人| 欲色天天网综合久久| 久久国产精品久久精品| 在线观看亚洲区| 成人免费网站在线观看| 精品中文字幕在线| 亚洲乱亚洲乱妇无码| 欧美另类极品videosbest最新版本| 日韩免费观看视频| 中文字幕亚洲欧美在线| 韩国三级日本三级少妇99| 亚洲高清一二三区| 成人天堂噜噜噜| 亚洲乱码一区av黑人高潮| 成人女保姆的销魂服务| 欧美日本国产在线| 日韩av片永久免费网站| 国产一区二区动漫| 亚洲国产精品成人va在线观看| 久久人人97超碰精品888| 国产精品久久久久久亚洲调教| 欧美性jizz18性欧美| 久久久视频免费观看| 国产精品久久久久久久久久东京| 国精产品一区一区三区有限在线| 日韩免费视频在线观看| 欧美激情手机在线视频| 国产日韩一区在线| 日韩电视剧免费观看网站| 亚洲人成五月天| 亚洲肉体裸体xxxx137| 国产精品午夜视频| 欧美区在线播放| 欧美极品xxxx| 91精品国产成人| 欧美色视频日本高清在线观看| 国产精品亚洲一区二区三区| 欧美精品18videos性欧| 国产福利精品视频| 久热国产精品视频| 影音先锋欧美在线资源| 国产精品久久久| 精品成人av一区| 日韩av色综合| 亚洲国模精品一区| 最新日韩中文字幕| 亚洲一区二区三区四区在线播放| 韩国福利视频一区| 色哟哟亚洲精品一区二区| 精品国产91乱高清在线观看| 久热精品视频在线免费观看| 中文欧美日本在线资源| 亚洲国产婷婷香蕉久久久久久| 成人xvideos免费视频| 国产精品视频一区二区高潮| 久久久精品免费| 久久成年人免费电影| 国产成人精品免高潮费视频| 亚洲全黄一级网站| 久久影视三级福利片| 国产精品中文久久久久久久| 国产精品扒开腿做爽爽爽的视频| 日本aⅴ大伊香蕉精品视频| 亚洲成人精品视频| 亚洲另类欧美自拍| 在线日韩av观看| 日韩欧美国产黄色| 97视频com| 欧美性生活大片免费观看网址| 国产精品成人品| 97热在线精品视频在线观看| 九九精品视频在线观看| 欧美日韩国产中文字幕| 狠狠躁夜夜躁人人躁婷婷91| 国产精品吊钟奶在线| 97色在线观看免费视频| 亚洲视频电影图片偷拍一区| 97视频在线观看亚洲| 亚洲缚视频在线观看| 91精品国产一区| 欧美黄色性视频| 精品亚洲aⅴ在线观看| 欧美日本啪啪无遮挡网站| 成人午夜在线观看| 久久成人av网站| www.欧美视频| 久久久久久久久久久人体| 91精品啪在线观看麻豆免费| 一区二区三区视频在线| 亚洲香蕉在线观看| 国产精品视频播放| 色偷偷偷综合中文字幕;dd| 国产激情视频一区| 久热精品视频在线免费观看| 4k岛国日韩精品**专区| 久久综合亚洲社区| 青青草成人在线| 欧美精品久久久久久久免费观看| 欧美激情在线有限公司| 国产精品高精视频免费| 日韩免费在线电影| 欧美孕妇毛茸茸xxxx| 亚洲欧洲中文天堂| 亚洲一区二区三区乱码aⅴ蜜桃女| 国产欧美日韩综合精品| 成人久久一区二区三区| 国产欧美一区二区三区四区| 性色av一区二区三区在线观看| 亚洲人在线观看| 精品视频久久久久久久| 亚洲国产日韩欧美在线图片|