#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 200005 #define ba 47 //#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; void Solve() { read(N); out((N - 2) * 180);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
#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 200005 #define ba 47 //#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 L; char s[20]; void Solve() { scanf("%s",s + 1); L = strlen(s + 1); int ans = 15 - L; for(int i = 1 ; i <= L ; ++i) { if(s[i] == 'o') ++ans; } if(ans >= 8) puts("YES"); else puts("NO"); } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
就是有\(C\)的機率往下摁,不然就中止,這樣的指望次數是\(\frac{C}{1 - C}\)node
咱們枚舉最終狀況走了\(i\)個\(A\)和\(N\)個\(B\)(反過來同理),這個時候\(A\)勝的機率是\(\frac{A}{A+ B}\),\(B\)勝的機率是\(\frac{B}{A+ B}\),指望次數就是\((N + i)(\frac{C}{1 - C} + 1)\)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 eps 1e-10 #define MAXN 100005 #define ba 47 //#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 fac[1000005],invfac[1000005]; int N,A,B,C; 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 &a,int b) { a = inc(a,b); } int cnm(int n,int m) { if(n < m) return 0; else return mul(fac[n],mul(invfac[m],invfac[n - m])); } int fpow(int x,int c) { int res = 1,t = x; while(c) { if(c & 1) res = mul(res,t); t = mul(t,t); c >>= 1; } return res; } void Solve() { read(N);read(A);read(B);read(C); A = mul(A,fpow(100,MOD - 2)); B = mul(B,fpow(100,MOD - 2)); C = mul(C,fpow(100,MOD - 2)); int iv = fpow(inc(1,MOD - C),MOD - 2); C = mul(C,iv); int k = fpow(inc(A,B),MOD - 2); A = mul(A,k);B = mul(B,k); fac[0] = 1; for(int i = 1 ; i <= 2 * N ; ++i) { fac[i] = mul(fac[i - 1],i); } invfac[2 * N] = fpow(fac[2 * N],MOD - 2); for(int i = 2 * N - 1 ; i >= 0 ; --i) { invfac[i] = mul(invfac[i + 1],i + 1); } int ans = 0; for(int i = 0 ; i < N ; ++i) { int h = inc(mul(fpow(A,N),fpow(B,i)),mul(fpow(B,N),fpow(A,i))); int t = mul(cnm(i + N - 1,N - 1),mul(C + 1,i + N)); t = mul(t,h); update(ans,t); } out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
大膽猜測一下發現就是除了最大值都加一遍,若是一個值加了兩遍會佔一個比它大的值得位置,不優,構造的話就是隨便選一個根而後按dfs序從大到小填數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 eps 1e-10 #define MAXN 10005 #define ba 47 //#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); } struct node { int to,next; }E[MAXN * 2]; int sumE,head[MAXN],N; int c[MAXN],ans; int p[MAXN],tot; void add(int u,int v) { E[++sumE].to = v; E[sumE].next = head[u]; head[u] = sumE; } void dfs(int u,int fa) { p[u] = c[tot--]; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(v != fa) { dfs(v,u); } } } void Solve() { read(N); int a,b; for(int i = 1 ; i < N ; ++i) { read(a);read(b);add(a,b);add(b,a); } for(int i = 1 ; i <= N ; ++i) read(c[i]); sort(c + 1,c + N + 1); for(int i = 1 ; i < N ; ++i) ans += c[i]; tot = N; dfs(1,0); out(ans);enter; for(int i = 1 ; i <= N ; ++i) { out(p[i]);space; } enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
沒作出來的我真是降智優化
若是d=0,那麼答案是\(x^{n}\)spa
若是d不爲0,都除上一個d,而後發現是一段連續的數相乘,能夠用前綴乘積的一個除另外一個,特判掉\(x = 0\)和\(\frac{x}{d} + n - 1 >= P\)的狀況,最後再乘上\(d^{n}\)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 10005 #define ba 47 //#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 = 1000003; int pre[MOD + 5]; int mul(int a,int b) { return 1LL * a * b % MOD; } int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; } int fpow(int x,int c) { int res = 1,t = x; while(c) { if(c & 1) res = mul(res,t); t = mul(t,t); c >>= 1; } return res; } void Solve() { pre[0] = 1; for(int i = 1 ; i < MOD ; ++i) pre[i] = mul(pre[i - 1],i); int Q,x,d,n; read(Q); for(int i = 1 ; i <= Q ; ++i) { read(x);read(d);read(n); if(d == 0) {out(fpow(x,n));enter;continue;} x = mul(x,fpow(d,MOD - 2)); if(x + n - 1 >= MOD || x == 0) {puts("0");continue;} int res = mul(pre[x + n - 1],fpow(pre[x - 1],MOD - 2)); res = mul(res,fpow(d,n)); out(res);enter; } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
設\(dpl[i][j]\)表示這個區間\([i,j]\)有一種方式是\(i\)能戰勝全部人get
\(dpr[i][j]\)表示有一種方式\(j\)能戰勝全部人it
答案就是\(dpr[1][x] = 1\)而且\(dpl[x][N] = 1\)的全部位置io
而後\(dpr[l][r]\)爲1的條件是存在\(k\)使得\(dpr[l][k] = 1\)而且\(dpl[k][r - 1] = 1\)而且\(a_{r,k} = 1\)class
\(dpl[l][r]\)是存在\(k\)使得\(dpr[l + 1][k] = 1\)而且\(dpl[k][r] = 1\)而且\(a_{l,k} = 1\)
這個能夠用bitset優化,因此複雜度是\(O(\frac{N^{3}}{w})\)
#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 10005 #define ba 47 //#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); } bitset<2005> a[2005],dpr[2005],dpl[2005],tmp; int N; char s[2005][2005]; void Solve() { read(N); for(int i = 2 ; i <= N ; ++i) { scanf("%s",s[i] + 1); for(int j = 1 ; j < i ; ++j) { if(s[i][j] == '1') a[i][j] = 1; else a[j][i] = 1; } } for(int i = 1 ; i <= N ; ++i) dpr[i][i] = 1,dpl[i][i] = 1; for(int d = 2 ; d <= N ; ++d) { for(int l = 1 ; l <= N ; ++l) { int r = l + d - 1; if(r > N) break; if((dpr[l] & dpl[r - 1] & a[r]).any()) { dpr[l][r] = 1; } if((dpl[r] & dpr[l + 1] & a[l]).any()) { dpl[r][l] = 1; } } } out((dpr[1] & dpl[N]).count());enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }