牛客每日練習 方塊 I,方塊 II,子串行

2021-10-04 23:45:33 字數 1597 閱讀 5017

有 n 個方塊排成一排,每個方塊都染有顏色,第 i 個的顏色為 ci,一共有三種顏色,分別為紅,黃,藍,現在你可以對相鄰的顏色不同的方塊進行施法,使其變成第三種顏色,比如對相鄰的紅方塊和黃方塊進行施法,就會使其合併為藍方塊。施法順序的不同,可能對最終的結果產生不同的影響,問在最優策略下,最少能剩下多少個方塊。
t組資料。

每組資料一行,將方塊序列用字串形式給出,a,b,c表示三種不同顏色的方塊。

t <= 10

1 <= n <= 5000

每組資料乙個整數,表示答案。
示例1

複製

abc
複製

2
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f

#define p pairtypedef long long ll;

using namespace std;

const int mod=1e9+7;

char s[5010];

int n;

int main()b[100005];

int c[100005],ct[100005];

bool cmp(node x,node y)

}printf("%d\n", jg);

}return 0;

}

給定乙個小寫字母字串t

求有多少長度為m的小寫字母字串s滿足,t是s的乙個子串行(不需要連續)

第一行乙個字串t

第二行乙個正整數m

輸出答案對109+7取模的值
示例1

複製

a

2

複製

51
長度為2的裡面有a的串有51種
1<=|t|,m<=105
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f

#define p pairtypedef long long ll;

using namespace std;

const int mod=1e9+7;

string s;

ll c[100010],jg,l,r,n;

ll ksm(ll a,ll b)

return res;

}ll c(ll a,ll b)

int main()

printf("%lld\n",jg);

return 0;

}

牛客每日練習 子串,主持人的煩惱,樹

給出乙個正整數n,我們把1.n在k進製下的表示連起來記為s n,k 例如s 16,16 123456789abcdef10,s 5,2 11011100101。現在對於給定的n和字串t,我們想知道是否存在乙個k 2 k 16 使得t是s n,k 的子串。第一行乙個整數n 1 n 50,000 第二行...

牛客每日練習 翻硬幣,s01串,乘積最大

小明正在玩乙個 翻硬幣 的遊戲。桌上放著排成一排的若干硬幣。我們用 表示正面,用 o 表示反面 是小寫字母,不是零 比如,可能情形是 oo oooo 如果同時翻轉左邊的兩個硬幣,則變為 oooo oooo 現在小明的問題是 如果已知了初始狀態和要達到的目標狀態,每次只能同時翻轉相鄰的兩個硬幣,那麼對...

牛客每日一題 合併回文子串(區間DP)

題目鏈結 題目描述 輸入兩個字串a和b,合併成乙個串c,屬於a和b的字元在c中順序保持不變。如 abc 和 xyz 可以被組合成 axbycz 或 abxcyz 等。我們定義字串的價值為其最長回文子串的長度 回文串表示從正反兩邊看完全一致的字串,如 aba 和 xyyx 需要求出所有可能的c中價值最...