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

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

C. Mahmoud and a Message 396 div2 C dp好題

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

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個字母每個字母的長度,規定每個字母所在子字符串不能超過這個長度,允許把原字符串進行分割。輸出有多少種分組方案。分組方案中子字符串最長是多少。最少的分組方案是多少。涉及到每個字母的決策。所以是dp,三個dp的問題合并,對于像我這樣的新手絕對是好題。 問題一:多少種分組方案。 狀態轉移方程 dp[0]=1 分組方案至少一個 ,從后往前,如果j字母所能在的長度符合i-j的長度 for i 1~n for j i-1~0 只要len>=i-j; 因為 len起碼為1 所以 i起碼比j大于1,才能不能更新。(關于基底的技巧)因為len>i-j 所以j可以和i在同一個子字符串,那么狀態轉移方程: dp[i]=dp[i]+dp[j] 因為dp[j]里面的所有方案沒有第j個字母也是可以單獨成立。然后一步步 j–,累加i-j的方案。知道len

#include <bits/stdc++.h>using namespace std;const int inf=(int)1e9;const int mod=inf+7;int a[30];int dp[3][2000];int main(){ int n; string s; while(cin>>n) { cin>>s; 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[s[j]-'a']); if(len<i-j) break; 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;}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品视频久久| 日韩美女av在线免费观看| 97色伦亚洲国产| 国产精品亚洲网站| 在线亚洲午夜片av大片| 欧美成人在线影院| 国产精品久久久久久久久久99| 韩国福利视频一区| 欧美激情亚洲激情| 秋霞av国产精品一区| 亚洲色图偷窥自拍| 日韩高清电影好看的电视剧电影| 色先锋资源久久综合5566| 国产精品成人一区二区三区吃奶| 亚洲精品456在线播放狼人| 日韩美女av在线免费观看| 欧美日韩国产中文精品字幕自在自线| 久久久久www| 欧美午夜片在线免费观看| 亚洲aⅴ日韩av电影在线观看| 国产精品海角社区在线观看| 国产精品成人va在线观看| 亚洲第一视频网站| 国产精品成人aaaaa网站| 亚洲美女www午夜| 亚洲一区二区久久久久久| 日韩av在线播放资源| 亚洲美女喷白浆| 日韩中文字幕av| 中文字幕亚洲天堂| 亚洲97在线观看| 精品久久久久久中文字幕一区奶水| 国产视频久久久久| 久久天天躁狠狠躁夜夜爽蜜月| 色综合久综合久久综合久鬼88| 国产精品午夜国产小视频| 欧美亚洲国产日韩2020| 久久久久www| 欧美黑人性生活视频| 国产综合色香蕉精品| 日韩中文字幕网址| 欧美日韩成人精品| 欧美另类极品videosbestfree| 亚洲男人av电影| 欧美日韩裸体免费视频| 国产亚洲欧洲黄色| 国产精品黄色av| 亚洲精品一区二区网址| 不用播放器成人网| 欧美最近摘花xxxx摘花| 国产精品扒开腿做爽爽爽男男| 国产精品狼人色视频一区| 午夜精品一区二区三区视频免费看| 韩国视频理论视频久久| 久久久国产一区二区三区| 成人免费福利在线| 国产午夜精品全部视频在线播放| 亚洲国产成人精品女人久久久| 自拍偷拍亚洲在线| 亚洲精品在线观看www| 在线视频中文亚洲| 欧美大片在线看免费观看| 亚洲欧洲免费视频| 欧美精品videos另类日本| 久久成人精品视频| 欧美日韩国产中文字幕| 欧美日韩午夜视频在线观看| 欧美激情日韩图片| 亚洲毛片在线免费观看| 日韩在线精品视频| 国产精品稀缺呦系列在线| 成人国产精品久久久久久亚洲| 亚洲激情视频在线播放| 波霸ol色综合久久| 欧美另类精品xxxx孕妇| 国产精品爱啪在线线免费观看| 亚洲国产天堂久久综合网| 亚洲社区在线观看| 国产v综合v亚洲欧美久久| 欧美日韩国产限制| 91成人性视频| 亚洲在线一区二区| 久久免费视频这里只有精品| 欧美激情在线有限公司| 国产精品扒开腿做爽爽爽的视频| 欧美老女人性视频| 欧美专区日韩视频| 日本午夜精品理论片a级appf发布| 久久久女女女女999久久| 狠狠躁天天躁日日躁欧美| 亚洲国产欧美日韩精品| 亚洲免费视频在线观看| 日本不卡视频在线播放| 亚洲人成免费电影| 久久91精品国产91久久跳| 俺去亚洲欧洲欧美日韩| 韩国国内大量揄拍精品视频| 国产精品久久久久久久久粉嫩av| 亚洲成人激情小说| 亚洲三级黄色在线观看| 亚洲天堂免费观看| 精品调教chinesegay| 亚洲欧美综合区自拍另类| 亚洲精品丝袜日韩| 中文字幕少妇一区二区三区| 国产一区二区av| 日本最新高清不卡中文字幕| 亚洲区中文字幕| 久久九九精品99国产精品| 久久韩国免费视频| 国产日韩精品在线观看| 中文字幕亚洲精品| 九九热精品视频| 日韩欧美国产黄色| 日韩人体视频一二区| 久久亚洲综合国产精品99麻豆精品福利| 日韩成人网免费视频| 欧美人成在线视频| 久久69精品久久久久久久电影好| 91精品国产91久久久| 97在线免费观看视频| 91精品久久久久久久| 视频一区视频二区国产精品| 亚洲午夜精品久久久久久性色| 尤物yw午夜国产精品视频| 成人黄在线观看| 色青青草原桃花久久综合| 欧美亚洲日本黄色| 亚洲福利影片在线| 亚洲一区二区免费| 久久久精品一区二区三区| 中文字幕在线视频日韩| 亚洲欧美资源在线| 日本成人激情视频| 亚洲男人天堂2024| 在线视频中文亚洲| 国产69精品久久久久9| 日韩在线播放一区| 91免费欧美精品| 欧美精品在线看| 一区二区三区国产在线观看| 黑人巨大精品欧美一区二区三区| 欧美午夜精品久久久久久浪潮| 日韩在线视频二区| 亚洲欧美日韩一区二区三区在线| 国产成人亚洲综合91| 日韩精品中文字幕视频在线| 欧美一区二区三区四区在线| 亚洲色图日韩av| 亚洲护士老师的毛茸茸最新章节| 日韩欧美国产中文字幕| 亚洲激情电影中文字幕| 亚洲色图15p| 日韩女在线观看| 久久久久久97| 亚洲成**性毛茸茸| 欧美日韩一区二区三区| 久久综合久久88| 久久久久久成人精品| 国产精品扒开腿做爽爽爽男男| 亚洲香蕉伊综合在人在线视看| 成人精品一区二区三区电影黑人| 欧美裸体xxxx极品少妇| 欧美孕妇孕交黑巨大网站|