日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Codeforces 508E Arthur and Brackets 区间dp

發(fā)布時間:2025/3/16 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces 508E Arthur and Brackets 区间dp 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Arthur and Brackets

區(qū)間dp, dp[ i ][ j ]表示第 i 個括號到第 j 個括號之間的所有括號能不能形成一個合法方案。

然后dp就完事了。

#include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ull unsigned long long using namespace std;const int N = 600 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8;int f[N][N]; int path[N][N];int n, L[N], R[N]; char ans[N << 1];int dp(int i, int j) {if(i > j) return true;if(~f[i][j]) return f[i][j];if(i == j) return L[i] <= 1 && R[i] >= 1;f[i][j] = false;for(int k = i; k <= j; k++) {if(2 * (k - i) + 1 < L[i] || 2 * (k - i) + 1 > R[i]) continue;if(dp(i + 1, k) && dp(k + 1, j)) {f[i][j] = true;path[i][j] = k - i;break;}}return f[i][j]; }void print(int i, int j, int start, int cnt) {if(i > j) return;ans[start] = '(';ans[start + cnt * 2 + 1] = ')';print(i + 1, i + cnt, start + 1, path[i + 1][i + cnt]);print(i + cnt + 1, j, start + 2 * cnt + 2, path[i + cnt + 1][j]); }int main() {memset(f, -1, sizeof(f));scanf("%d", &n);ans[2 * n + 1] = '\0';for(int i = 1; i <= n; i++) scanf("%d%d", &L[i], &R[i]);if(!dp(1, n)) puts("IMPOSSIBLE");else {print(1, n, 1, path[1][n]);puts(ans + 1);}return 0; }/* */

?

??

轉(zhuǎn)載于:https://www.cnblogs.com/CJLHY/p/10391579.html

總結(jié)

以上是生活随笔為你收集整理的Codeforces 508E Arthur and Brackets 区间dp的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。