\(A\)
He wants direct transfer
typedef long long ll;
const int N=55;
ll f[N][2];int a[N],n,p;
int main(){
scanf("%d%d",&n,&p);
fp(i,1,n)scanf("%d",&a[i]),a[i]&=1;
f[0][0]=1;
fp(i,1,n){
f[i][0]=f[i-1][0],f[i][1]=f[i-1][1];
if(a[i]&1)f[i][0]+=f[i-1][1],f[i][1]+=f[i-1][0];
else f[i][0]+=f[i-1][0],f[i][1]+=f[i-1][1];
}
printf("%lld\n",f[n][p]);
return 0;
}
\(B\)
I'm a \ (ZZ \) ......
The contribution of each number is either positive or negative, then we enumerate a few positive contribution, then count the sum of the contribution of upper and lower bounds on the line
typedef long long ll;
int n,a,b,c,d;ll l,r;
int main(){
scanf("%d%d%d%d%d",&n,&a,&b,&c,&d),b-=a;
fp(i,0,n-1){
l=1ll*i*c-1ll*(n-1-i)*d;
r=1ll*i*d-1ll*(n-1-i)*c;
if(b>=l&&b<=r)return puts("YES"),0;
}
puts("NO");
return 0;
}
\(C\)
My mind is filled with a paste of it ......
For a number \ (i \) , if there \ (cnt [i] \) times, then we can be seen as the \ ([i-cnt [i ] + 1, i] \) position to add a section , it is need to change the number of \ (0 \) number of locations, then the modification may \ (O (1) \)
//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
int cnt[N],vis[N],a[N],n,m,res;
inline void ins(R int x){++cnt[x];if(x-cnt[x]+1>=1&&!vis[x-cnt[x]+1]++)--res;}
inline void del(R int x){if(x-cnt[x]+1>=1&&!--vis[x-cnt[x]+1])++res;--cnt[x];}
int main(){
scanf("%d%d",&n,&m),res=n;
fp(i,1,n)scanf("%d",&a[i]),ins(a[i]);
for(R int i=1,x,y;i<=m;++i){
scanf("%d%d",&x,&y);
del(a[x]),a[x]=y,ins(a[x]);
printf("%d\n",res);
}
return 0;
}
\(D\)
Like a long time to see the results of a solution to a problem found no gods conclusion ......
We consider each of them sub-tree \ (sg \) value, if it is a leaf, then \ (sg (U) = 0 \) , otherwise, each son is equivalent to a sub-game, calculate the son node \ (v \) of \ (sg \) after the value, then \ (v \) subtree plus \ ((u, v) \ ) of this edge \ (sg \) value is \ (sg (v) +1 \ )
Proof, and if deleted is \ ((u, v) \ ) this edge, then \ (sg = 0 \) , otherwise the assumption deleted is \ (v \) a tree subtree side, obtained by \ (V \) original subtree \ (T \) a can be obtained \ (T '\) , if we use induction, then \ (sg (T') \ ) can take over \ ( [0 + 1,1 + 1,2 +. 1, ..., SG (T) +. 1 -1] \) , so \ (sg (u) = sg (T) +1 \)
//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int sg[N],n;
void dfs(int u,int fa){
sg[u]=0;
go(u)if(v!=fa)dfs(v,u),sg[u]^=sg[v]+1;
}
int main(){
scanf("%d",&n);
for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
dfs(1,0);
puts(sg[1]?"Alice":"Bob");
return 0;
}
\(E\)
For each point \ (I \) , if the \ (c_i = 0 \) then let \ (l = a_i \) otherwise disposed \ (L = -c_i \) , if the \ (d_i = 0 \) then let \ ( r = -b_i \) otherwise, let \ (r = D_i \) , we found that if \ ((li, ri) \ ) can be connected to the \ ((l, r) \ ) on the right side if and only if \ (li = r \)
So we \ ((l, r) \ ) as the \ (L \) is connected to the \ (R & lt \) of one edge, then this should now exploded into a number of paths, such that at the beginning of each path is a positive number , the end is negative. Then clearly a positive number that is greater than equal to the degree, and negative-degree not less than a degree, and at least out of a point is not equal to the degree (otherwise the thing a ring and, for each communication block never have the decomposition into a number of paths)
//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=405;
int fa[N],vis[N],in[N],out[N],n,h;
inline int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
scanf("%d%d",&n,&h);
fp(i,0,h<<1)fa[i]=i;
for(R int i=1,a,b,c,d,l,r;i<=n;++i){
scanf("%d%d%d%d",&a,&b,&c,&d);
l=(c?-c:a)+h,r=(d?d:-b)+h,fa[find(l)]=find(r);
++out[l],++in[r];
}
fp(i,-h,-1)if(out[i+h]>in[i+h])return puts("NO"),0;
fp(i,1,h)if(in[i+h]>out[i+h])return puts("NO"),0;
fp(i,0,h<<1)if(in[i]!=out[i])vis[find(i)]=1;
fp(i,0,h<<1)if(in[i]&&out[i]&&!vis[find(i)])return puts("NO"),0;
puts("YES");
return 0;
}
\(F\)
First, the path can be compressed into a binary number, so that it can write a violent \ (O (2 ^ {2n }) \) a \ (DP \)
Consider how optimization, we found a legitimate path, if and only if at any time before the prefix and are less and a path prefix
Now consider the set of \ (I \) path, then the front force \ (j-1 \) one and the same step, the account of the \ (J \) Step
If the same direct disregard of, or if the previous step away \ (1 \) so far to go \ (0 \) apparently \ (GG \) , you only need to consider the previous step away \ (1 \) so far to go \ (0 \)
We find \ (i-1 \) next \ (1 \) position, and then put that \ (1 \) position to move to the front, so restrictions are still lawful
If there is a next \ (1 \) then the current road apparently can easily go
Less direct \ (dp \) on it
//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
R int res=1;
for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
return res;
}
const int N=(1<<20)+5;
int f[25][N],g[N],is[25][25],nxt[N][25],n,m,k,res,lim;
int main(){
// freopen("testdata.in","r",stdin);
scanf("%d%d%d",&n,&m,&k),--n,lim=(1<<n);
memset(is,-1,sizeof(is));
for(R int i=1,a,b,c;i<=k;++i)scanf("%d%d%d",&a,&b,&c),is[a][b-1]=c;
fp(s,0,lim-1){
R int p=-1;
fd(i,n-1,0){
if(s>>i&1)p=i;
nxt[s][i]=p;
}
}
f[n][0]=1;
fp(i,1,m){
fp(j,0,lim-1)g[j]=f[n][j];
memset(f,0,sizeof(f));
fp(j,0,lim-1)f[0][j]=g[j];
fp(j,0,n-1)fp(k,0,lim-1)if(f[j][k])
fp(l,0,1){
if(is[i][j]!=-1&&l!=is[i][j])continue;
R int t=k>>j&1;
if(l==0&&t==1)continue;
if(l==t)upd(f[j+1][k],f[j][k]);
else{
R int p=nxt[k][j];
if(p==-1)upd(f[j+1][k|(1<<j)],f[j][k]);
else upd(f[j+1][k^(1<<j)^(1<<p)],f[j][k]);
}
}
}
fp(i,0,lim-1)upd(res,f[n][i]);
printf("%d\n",res);
return 0;
}