"Training log 18" (8.16) recognize their own

A few days before the first title of the pigeon

T1 mine

  Simple $ dp $, meaning you can divert attention.

  My definition of too much trouble, but I refer to other chiefs of blog attention.

  Defined $ f_ {i, j, k} $ indicates the current position $ i $, the current element is $ j $, the $ k $ is an element of the program number. i dimension you can roll up.

  Nothing to say, little trouble is $? $ And $ 1 $, and the other to simulate transfer it.

  Brother Fucai.

  1 #include<cstdio>
  2 #include<string>
  3 #include<iostream>
  4 #include<cstring>
  5 #define LL long long
  6 #define HZOI std
  7 using namespace HZOI;
  8 const int mod=1e9+7;
  9 LL ans;
 10 int n;
 11 char s[1000003],a[1000003];
 12 LL dp[1000003][5][5];
 13 inline void Mod(LL &a) {while (a>=mod) a-=mod;}
 14 int main()
 15 {
 16     char cc=getchar();
 17     while (cc!='0' and cc!='1' and cc!='2' and cc!='*' and cc!='?') cc=getchar();
 18     while (cc=='0' or cc=='1' or cc=='2' or cc=='*' or cc=='?') 
 19     {
 20         if (cc=='?') a[++n]=4;
 21         else if (cc=='*') a[++n]=3;
 22         else a[++n]=cc-48;
 23         cc=getchar();
 24     }
 25     if (a[1]!=4 and a[2]!=4) dp[2][a[2]][a[1]]=1;
 26     if (a[1]==4 and a[2]!=4)
 27     {
 28         if (!a[2])
 29             dp[2][a[2]][0]=1;
 30         if (a[2]==1)
 31             dp[2][a[2]][0]=dp[2][a[2]][3]=1;
 32         if (a[2]==2)
 33             dp[2][a[2]][3]=1;
 34         if (a[2]==3)
 35             dp[2][a[2]][3]=dp[2][a[2]][1]=1;
 36     }
 37     if (a[1]!=4 and a[2]==4)
 38     {
 39         if (!a[1])
 40             dp[2][0][a[1]]=dp[2][1][a[1]]=1;
 41         if (a[1]==1)
 42             dp[2][3][a[1]]=1;
 43         if (a[1]==2) return puts("0"),0;
 44         if (a[1]==3)
 45             dp[2][1][a[1]]=dp[2][2][a[1]]=dp[2][3][a[1]]=1;
 46     }
 47     if (a[1]==4 and a[2]==4)
 48     {
 49         dp[2][0][0]=dp[2][1][0]=dp[2][3][1]=dp[2][1][3]=dp[2][2][3]=dp[2][3][3]=1;
 50     }
 51     for (int i=3; i<=n; ++i)
 52     {
 53         if (!a[i])
 54             for (int j=0; j<3; ++j)
 55             {
 56                 if (!j)
 57                     for (int k=0; k<2; ++k)
 58                         Mod(dp[i][0][j]+=dp[i-1][j][k]);
 59                 if (j==1)
 60                     Mod(dp[i][0][j]+=dp[i-1][j][3]);
 61             }
 62         if (a[i]==1)
 63             for (int j=0; j<4; ++j)
 64             {
 65                 if (!j)
 66                     for (int k=0; k<2; ++k)
 67                         Mod(dp[i][1][j]+=dp[i-1][j][k]);
 68                 if (j==1)
 69                     Mod(dp[i][1][j]+=dp[i-1][j][3]);
 70                 if (j==3)
 71                     for (int k=1; k<4; ++k)
 72                         Mod(dp[i][1][j]+=dp[i-1][j][k]);
 73             }    
 74         if (a[i]==2)
 75             for (int j=1; j<4; ++j)
 76                 Mod(dp[i][2][3]+=dp[i-1][3][j]);
 77         if (a[i]==3)
 78             for (int j=1; j<4; ++j)
 79             {
 80                 if (j==1)
 81                     for (int k=0; k<2; ++k)
 82                         Mod(dp[i][3][j]+=dp[i-1][j][k]);
 83                 if (j==2)
 84                     Mod(dp[i][3][j]+=dp[i-1][j][3]);
 85                 if (j==3)
 86                     for (int k=1; k<4; ++k)
 87                         Mod(dp[i][3][j]+=dp[i-1][j][k]);
 88             }
 89         if (a[i]==4)
 90             for (int g=0; g<4; ++g)
 91             {
 92                 if (!g)
 93                     for (int j=0; j<3; ++j)
 94                     {
 95                         if (!j)
 96                             for (int k=0; k<2; ++k)
 97                                 Mod(dp[i][0][j]+=dp[i-1][j][k]);
 98                         if (j==1)
 99                             Mod(dp[i][0][j]+=dp[i-1][j][3]);
100                     }
101                 if (g==1)
102                     for (int j=0; j<4; ++j)
103                     {
104                         if (!j)
105                             for (int k=0; k<2; ++k)
106                                 Mod(dp[i][1][j]+=dp[i-1][j][k]);
107                         if (j==1)
108                             Mod(dp[i][1][j]+=dp[i-1][j][3]);
109                         if (j==3)
110                             for (int k=1; k<4; ++k)
111                                 Mod(dp[i][1][j]+=dp[i-1][j][k]);
112                     }    
113                 if (g==2)
114                     for (int j=1; j<4; ++j)
115                         Mod(dp[i][2][3]+=dp[i-1][3][j]);
116                 if (g==3)
117                     for (int j=1; j<4; ++j)
118                     {
119                         if (j==1)
120                             for (int k=0; k<2; ++k)
121                                 Mod(dp[i][3][j]+=dp[i-1][j][k]);
122                         if (j==2)
123                             Mod(dp[i][3][j]+=dp[i-1][j][3]);
124                         if (j==3)
125                             for (int k=1; k<4; ++k)
126                                 Mod(dp[i][3][j]+=dp[i-1][j][k]);
127                     }
128             }
129     }
130     Mod(ans+=dp[n][0][0]+dp[n][0][1]+dp[n][1][3]+dp[n][3][1]+dp[n][3][2]+dp[n][3][3]);
131     printf("%lld\n",(ans+mod)%mod);
132 }
mine

 

T2 water

  When there is no in-depth examination of understanding the problem, resulting in Mongolia to $ 20 $ points.

  In fact, the idea is not difficult, but I did not expect when the examination.

  This question is a main idea, from the beginning to the inside border sweep with state borders update the internal state, you can find a minimum flow out of the mouth, which is the key to solving the problem.

  We can consider $ SPFA $ traverse the entire map, and then continue to update its value with the dis answer, be careful not to be considered the starting point of $ dis $, should also consider the value end of $ a $, whichever is $ max $, because I make sure the answer to the situation "back" does not appear.

  Brother Fucai.

  

 1 #include<cstdio>
 2 #include<cstring>
 3 #define LL long long
 4 #define HZOI std
 5 using namespace HZOI;
 6 int n,m;
 7 LL head,tail,a[303][303],dis[303][303],vis[303][303],quei[1000003],quej[1000003];
 8 int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
 9 inline void Bfs();
10 inline LL read();
11 inline LL max(LL a,LL b) {return a>b?a:b;}
12 inline LL min(LL a,LL b) {return a<b?a:b;}
13 int main()
14 {
15     n=read(),m=read();
16     for (int i=1; i<=n; ++i)
17         for (int j=1; j<=m; ++j)
18             a[i][j]=read();
19     memset(dis,0x3f,sizeof(dis));
20     head=tail=0;
21     for (int i=1; i<=n; ++i)
22     {
23         dis[i][m]=max(0,a[i][m]);
24         dis[i][1]=max(0,a[i][1]);
25         if (!vis[i][m]) quei[++tail]=i, quej[tail]=m, vis[i][m]=1;
26         if (!vis[i][1]) quei[++tail]=i, quej[tail]=1, vis[i][1]=1;
27     }
28     for (int i=1; i<=m; ++i)
29     {
30         dis[n][i]=max(0,a[n][i]);
31         dis[1][i]=max(0,a[1][i]);
32         if (!vis[n][i]) quei[++tail]=n, quej[tail]=i, vis[n][i]=1;
33         if (!vis[1][i]) quei[++tail]=1, quej[tail]=i, vis[1][i]=1;
34     }
35     Bfs();
36     for (int i=1; i<=n; ++i)
37     {
38         for (int j=1; j<=m; ++j)
39             printf("%lld ",dis[i][j]-a[i][j]);
40         puts("");
41     }
42 }
43 inline void Bfs()
44 {
45     while (head^tail)
46     {
47         int xi=quei[++head],xj=quej[head];
48         vis[xi][xj]=0;
49         for (int i=0; i<4; ++i)
50         {
51             int toi=xi+dx[i],toj=xj+dy[i];
52             if (toi>0 and toi<=n and toj>0 and toj<=m)
53             {
54                 int dtc=max(a[toi][toj],dis[xi][xj]);
55                 if (dis[toi][toj]>dtc)
56                 {
57                     dis[toi][toj]=dtc;
58                     if (!vis[toi][toj]) quei[++tail]=toi,quej[tail]=toj,vis[toi][toj]=1;
59                 }
60             }
61         }
62     }
63 }
64 inline LL read()
65 {
66     LL nn=0,ff=1; char cc=getchar();
67     while (cc<'0' or cc>'9') {if (cc=='-') ff=-1; cc=getchar();}
68     while (cc>='0' and cc<='9') nn=(nn<<3)+(nn<<1)+(cc^48),cc=getchar();
69     return nn*ff;
70 }
water

 

Guess you like

Origin www.cnblogs.com/LH-Xuanluo/p/11366524.html