UVA1630 Folding 區間動態規劃

2021-08-08 05:39:37 字數 695 閱讀 5290

摺疊乙個字串,使得其成為乙個盡量短的字串 例如aaaaaa變成6(a)而且這個摺疊是可以巢狀的,例如 neeeeeryesyesyesneeeeeryesyesyes 會變成 2(n5(e)r3(yes))。

用dp[i][j]表示i~j壓縮的最小長度

dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]
#include 

#include

#include

#include

#include

#include

#include

using

namespace

std;

const

int maxn = 105;

string dp[maxn][maxn], str;

int n;

int zig(int l, int r)

if( chk ) return l;

}return0;}

#define inf 0x3f3f3f3f

void work()

dp[i][j]=dp[i][p]+dp[p+1][j];

int len = zig(i,j);

if( len )

} }int main()

題解 UVA1630 串摺疊 Folding

題目描述 摺疊的定義如下 乙個字串可以看成它自身的摺疊。記作s s x s 是x x 1 個s連線在一起的串的摺疊。記作x s ssss s x個s 如果a a b b 則ab a b 例如,因為3 a aaa,2 b bb,所以3 a c2 b aaacbb,而2 3 a c 2 b aaacaa...

UVA 1630 記憶化搜尋

輸入乙個字串,摺疊成乙個盡量短的串。問最短可以摺疊成什麼樣子的乙個串。設dp i j 為字串i到j摺疊成最短的字串後的長度,ss i j 為字串i到j摺疊成的最短的字串。dfs 記憶化搜尋即可。輸入的字串右邊界為str.size 1,需要特別注意。include include include in...

UVA 10382 (區間貪心)

注意每個圓管轄的區間不是最左或最右的端點而是和被覆蓋圖形的交點。直接按照每個圓的left排序 每次盡量尋找靠右的就可以了。include include include include include include include include include include include i...