Advertisement
AquaBlitz11

การดําเนินการซือกีตีกา (toi11_segitiga)

Mar 7th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. #define N 300
  4.  
  5. int main()
  6. {
  7.     for (int _ = 0; _ < 20; ++_) {
  8.  
  9.         int n;
  10.         char s[N];
  11.         bool can[N][N][3] = {};
  12.         scanf("%d %s", &n, s);
  13.  
  14.         for (int i = 0; i < n; ++i)
  15.             can[i][i][s[i]-'0'] = true;
  16.        
  17.         for (int z = 2; z <= n; ++z) {
  18.             for (int i = 0; i <= n-z; ++i) {
  19.                 int j = i+z-1;
  20.                 for (int k = i; k < j; ++k) {
  21.                     can[i][j][0] |= (can[i][k][0] && can[k+1][j][2]);
  22.                     can[i][j][1] |= (can[i][k][0] && can[k+1][j][1])
  23.                     || (can[i][k][1] && can[k+1][j][1])
  24.                     || (can[i][k][1] && can[k+1][j][2])
  25.                     || (can[i][k][2] && can[k+1][j][0])
  26.                     || (can[i][k][2] && can[k+1][j][2]);
  27.                     can[i][j][2] |= (can[i][k][0] && can[k+1][j][0])
  28.                     || (can[i][k][1] && can[k+1][j][0])
  29.                     || (can[i][k][2] && can[k+1][j][1]);
  30.                 }
  31.             }
  32.         }
  33.  
  34.         printf("%s\n", can[0][n-1][0] ? "yes" : "no");
  35.  
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement