Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : Segi Tiga
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 02 January 2023 [21:45]
- */
- #include<bits/stdc++.h>
- using namespace std;
- int res[3][3] = {2,1,0,2,1,1,1,2,1};
- int dp[260][260][3];
- char a[260];
- bool recur(int l,int r,int target){
- if(l == r) return (a[l] - '0' == target);
- if(dp[l][r][target] != -1) return dp[l][r][target];
- for(int k=l;k<r;k++){
- for(int i=0;i<=2;i++){
- for(int j=0;j<=2;j++){
- if(res[i][j] != target) continue;
- if(recur(l,k,i) && recur(k+1,r,j))
- return dp[l][r][target] = 1;
- }
- }
- }
- return dp[l][r][target] = 0;
- }
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int q = 20;
- while(q--){
- int n;
- cin >> n >> a+1;
- memset(dp,-1,sizeof dp);
- if(recur(1,n,0)) cout << "yes\n";
- else cout << "no\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment