每次取兩個相同的且最大的邊,取兩次便可c++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 100005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N,a[MAXN]; map<int,int> zz; void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) {read(a[i]);zz[a[i]]++;} int r = 0,c = 0; while(1) { if(zz.empty()) break; auto t = *(--zz.end());zz.erase(--zz.end()); if(t.se >= 2) { if(!r) r = t.fi; else if(!c) c = t.fi; } if(t.se > 2) zz[t.fi] = t.se - 2; if(r && c) break; } out(1LL * r * c);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
就是若是是
豎條對兩個長條,那麼方案數乘上2
豎條對豎條,乘上2
兩個長條+豎條,方案數乘上1
兩個長條+兩個長條 有3種
1 2
2 1
和
1 3
2 1
和
1 2
2 3算法
初始若是一個豎條有3種,兩個橫條有6種dom
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 100005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int MOD = 1000000007; int N,f[65]; char s[2][65]; int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; } int mul(int a,int b) { return 1LL * a * b % MOD; } void Solve() { read(N); scanf("%s%s",s[0] + 1,s[1] + 1); int ans = 0; for(int i = 1 ; i <= N ; ++i) { if(s[0][i] == s[0][i + 1]) continue; if(s[0][i - 1] == s[0][i]) { if(i <= 2) ans = 6; else { if(f[i - 2] == 0) ans = mul(ans,3); else if(f[i - 2] == 1) ans = mul(ans,2); } f[i] = 0; } else { if(i <= 1) ans = 3; else { if(f[i - 1] == 1) ans = mul(ans,2); } f[i] = 1; } } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
撞題了吧,最短不公共子串的那個模板大禮包spa
直接建序列自動機,求最短路,每次從前日後遍歷走一條最短路邊code
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 200005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } char a[MAXN]; int nxt[MAXN][26],N,dis[MAXN]; string ans = ""; void Solve() { scanf("%s",a + 1); N = strlen(a + 1); for(int i = 0 ; i < 26 ; ++i) nxt[N][i] = N + 1; for(int i = N - 1 ; i >= 0 ; --i) { for(int j = 0 ; j < 26 ; ++j) nxt[i][j] = nxt[i + 1][j]; nxt[i][a[i + 1] - 'a'] = i + 1; } dis[N + 1] = 0; for(int i = N ; i >= 0 ; --i) { dis[i] = N + 1; for(int j = 0 ; j < 26 ; ++j) dis[i] = min(dis[nxt[i][j]] + 1,dis[i]); } int pos = 0; while(pos != N + 1) { for(int i = 0 ; i < 26 ; ++i) { if(dis[nxt[pos][i]] + 1 == dis[pos]) { ans += (i + 'a'); pos = nxt[pos][i]; break; } } } cout << ans << endl; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
咱們認爲一個長方形任意一個22的方格若是包含偶數個黑點
那麼必定會變成全黑
咱們把每一個22的方格中間標記成一個新點,判斷可否選擇,而後用最大子矩形的算法作ip
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 2005 #define eps 1e-12 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int H,W,ans; char s[MAXN][MAXN]; int tr[MAXN],tl[MAXN],h[MAXN],l[MAXN],r[MAXN]; bool check(int x,int y) { return ((s[x - 1][y - 1] == '#') + (s[x - 1][y] == '#') + (s[x][y - 1] == '#') + (s[x][y] == '#')) & 1; } void Solve() { read(H);read(W); ans = max(H,W); for(int i = 0 ; i < H ; ++i) { scanf("%s",s[i]); } for(int i = 1 ; i <= W - 1; ++i) l[i] = 0,r[i] = W; tr[W] = W; for(int i = 1 ; i < H ; ++i) { for(int j = 1 ; j < W ; ++j) { if(check(i,j)) tl[j] = j; else tl[j] = tl[j - 1]; } for(int j = W - 1 ; j >= 1 ; --j) { if(check(i,j)) tr[j] = j; else tr[j] = tr[j + 1]; } for(int j = 1 ; j < W ; ++j) { if(check(i,j)) { h[j] = 0,l[j] = 0,r[j] = W; } else { l[j] = max(tl[j],l[j]); r[j] = min(tr[j],r[j]); h[j]++; ans = max(ans,(r[j] - l[j] - 1 + 1) * (h[j] + 1)); } } } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }