爲啥這場ARC那麼水……一個點就切完了c++
枚舉就行app
#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 eps 1e-10 #define MAXN 100005 //#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; int64 a[105]; void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) read(a[i]); int64 ans = 1e18; for(int64 i = -100 ; i <= 100 ; ++i) { int64 tmp = 0; for(int j = 1 ; j <= N ; ++j) { tmp += (a[j] - i) * (a[j] - i); } ans = min(ans,tmp); } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
要麼是兩個相鄰的字母相同,要麼是兩個相同的字母中間隔了一個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 eps 1e-10 #define MAXN 100005 //#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 s[MAXN]; int N; void Solve() { scanf("%s",s + 1); N = strlen(s + 1); for(int i = 1 ; i < N ; ++i) { if(s[i] == s[i + 1]) {out(i);space;out(i + 1);enter;return;} if(i != N - 1) { if(s[i] == s[i + 2]) {out(i);space;out(i + 2);enter;return;} } } out(-1);space;out(-1);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
每一個值其實能夠分開考慮get
設\(dp[i][j]\)爲前i個數指數的總和爲j的和,枚舉下一個數的指數,計算從\([A_{i + 1},B_{i + 1}]\)的全部狀況,更新便可it
#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 eps 1e-10 #define MAXN 405 //#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; int C,A[MAXN],B[MAXN]; int num[MAXN][MAXN],sum[MAXN][MAXN]; int dp[2][MAXN]; 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 update(int &x,int y) { x = inc(x,y); } void Solve() { read(N);read(C); for(int i = 1 ; i <= N ; ++i) read(A[i]); for(int i = 1 ; i <= N ; ++i) read(B[i]); for(int i = 1 ; i <= 400 ; ++i) { num[i][0] = 1; for(int j = 1 ; j <= 400 ; ++j) { num[i][j] = mul(num[i][j - 1],i); } } for(int j = 0 ; j <= 400 ; ++j) { for(int i = 1 ; i <= 400 ; ++i) { sum[i][j] = inc(sum[i - 1][j],num[i][j]); } } int cur = 0;dp[cur][0] = 1; for(int i = 1 ; i <= N ; ++i) { memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1])); for(int j = 0 ; j <= C ; ++j) { for(int h = 0 ; h <= C - j ; ++h) { update(dp[cur ^ 1][j + h],mul(dp[cur][j],inc(sum[B[i]][h],MOD - sum[A[i] - 1][h]))); } } cur ^= 1; } out(dp[cur][C]);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
這個題就是,我若是新加一個值,默認和我須要的下一位相同,而我摁下一個B後,當前最後一位的值就沒必要要是和s中對應位置相同了,因而方案數乘2class
設\(dp[i][j]\)爲第i次操做,字符串長度爲j,這樣dp便可date
#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 eps 1e-10 #define MAXN 5005 //#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 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 update(int &x,int y) { x = inc(x,y); } char s[5005]; int dp[5005][5005],N,L; void Solve() { read(N); scanf("%s",s + 1); L = strlen(s + 1); dp[0][0] = 1; for(int i = 0 ; i < N ; ++i) { for(int j = 0 ; j <= N ; ++j) { if(j == 0) update(dp[i + 1][j],dp[i][j]); else update(dp[i + 1][j - 1],mul(dp[i][j],2)); update(dp[i + 1][j + 1],dp[i][j]); } } out(dp[N][L]);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }