Winter training day1

T2: draw
First of all, observe the problem, and find that the operation of walking back and forth is very similar to the dp problem of a certain year of NOIP. First, observe the problem, and find that the operation of walking back and forth is very similar to the dp problem of a certain year of NOIP. First, observe the problem, and find that the operation of walking back and forth is very similar to the dp problem of a certain year of NOIP
So use the routine twice, so use the routine twice, so use the routine twice
My first thought was that I would only walk to the right or down, so I would walk to the end if I could. Later, I found that I could walk twice, and I thought I couldn't, but I found that I couldn't judge the situation where there was only one path. My first thought was that I could walk only to the right or down, so I could walk to the end. Later, I found that I could walk twice, and I thought I couldn't, but I found that I couldn't judge only one path My first thought was that I would only walk to the right or down, so if I could walk, I would walk to the end. Later, I found that I could not walk twice, but I found that I could not judge the situation where there was only one path
Positive solution: positive solution: positive solution:
For the first path: go down, go right if you can't go for the first path: go down, go right if you can't go for the first path: go down, go right if you can't
For the second path, if you can go right, go right, if you can't go down, for the second path, if you can go right, go right, if you can't go down, for the second path, if you can go right, go right, if you can't go down, go down
For coincident points multiplied by 2, because the path to the coincident point can be interchanged for the first and second points multiplied by 2, because the path to the coincident point can be interchanged for the first and second points multiplied by 2, because the path to the coincident point can be interchanged for the first and second points
Notes: Notes: Notes:

1. If a continuous coincidence point is encountered, it is only multiplied by 1 times 2, because for a continuous coincidence point, the path between the coincidence points is unique, and interchange will not produce a new scheme
2. The path exchange between the two ending points can only be calculated once. If it is exchanged twice, it is the same as the original scheme (the ending point is calculated in my code)
3. The continuous path at the beginning of the starting point cannot be included in the answer (if the ending point is calculated as I do)
```#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e5+5;//
int a[N],b[N],suma[N],sumb[N];
int n;
ll ans=1,mod=1e9+7;//
bool flag=false,flag2=false;//
void dfs(int x,int y,int xx,int yy,bool ff){//ff is used to judge continuous coincidence points
if(suma[x]>a[x]||sumb[y]>b[y]||suma[xx]>a[xx]||sumb[yy]>b[yy]) {if(x==xx&&y==yy) ans/=2;return;};
if(x!=xx||y!=yy){
flag=true;
}
if(x==n&&y==n&&xx==n&&yy==n){
flag2=true;
return;
}
if(suma[x]+1<=a[x]&&sumb[yy]+1<=b[yy]&&y+1<=n&&xx+1<=n){
suma[x]++,sumb[yy]++;
bool f=false;
if(x!=xx+1||y!=yy+1)sumb[y+1]++,suma[xx+1]++;
if(x==xx+1&&y+1==yy) {if(!ff) ans=ans*2%mod;f=true;};
dfs(x,y+1,xx+1,yy,f);
suma[x]--,sumb[yy]--;
if(x!=xx+1||y!=yy+1)sumb[y+1]--,suma[xx+1]--;
}
if(suma[x]==a[x]&&x+1<=n&&xx+1<=n&&sumb[yy]+1<=b[yy]){
suma[x+1]++,sumb[yy]++;
bool f=false;
if(x+1!=xx+1||y!=yy)suma[xx+1]++,sumb[y]++;
if(x+1==xx+1&&y==yy){if(!ff) ans=ans*2%mod;f=true;}
dfs(x+1,y,xx+1,yy,f);
suma[x+1]--,sumb[yy]--;
if(x+1!=xx+1||y!=yy)suma[xx+1]--,sumb[y]--;
}
if(sumb[yy]==b[yy]&&yy+1<=n&&y+1<=n&&suma[x]+1<=a[x]){
suma[x]++,sumb[yy+1]++;
bool f=false;
if(x!=xx||y+1!=yy+1)suma[xx]++,sumb[y+1]++;
if(x==xx&&y+1==yy+1){if(!ff) ans=ans*2%mod;f=true;}
dfs(x,y+1,xx,yy+1,f);
suma[x]--,sumb[yy+1]--;
if(x!=xx||y+1!=yy+1)suma[xx]--,sumb[y+1]--;
}
if(sumb[yy]==b[yy]&&suma[x]==a[x]&&x+1<=n&&yy+1<=n){
sumb[y]++;suma[xx]++;
bool f=false;
if(x+1!=xx||y!=yy+1)suma[x+1]++,sumb[yy+1]++;
if(x+1==xx&&y==yy+1){if(!ff) ans=ans*2%mod;f=true;}
dfs(x+1,y,xx,yy+1,f);
sumb[y]--;suma[xx]--;
if(x+1!=xx||y!=yy+1)suma[x+1]--,sumb[yy+1]--;
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
flag2=false;flag=false;
memset(suma,0,sizeof(suma));
memset(sumb,0,sizeof(sumb));
scanf("%d",&n);	ans=1;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++){
scanf("%d",&b[i]);
}
suma[1]++,sumb[1]++;
dfs(1,1,1,1,1);
if(!flag2){
puts("0");
continue;
}
if(!flag){
puts("1");
continue;
}
printf("%lld\n",ans);
}
}

```
Published 82 original articles, won praise 5, visited 1449

Posted on Sun, 12 Jan 2020 05:01:31 -0500 by jasongr