zoukankan      html  css  js  c++  java
  • 【 henuacm2016级暑期训练-动态规划专题 A 】Cards

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    很显然只要维护B,R,G的数量就好了。 可以很容易想到一个dfs(int a,int b,int c) 然后如果a+b+c==1,那么让其中为1的对应的颜色标记为可以得到就好 变换就是a-1,b-1,c+1和a-1,c-1,b+1以及b--,c--,a++以及a-1,b,c和a,b-1,c和a,b,c-1

    然后加一个记忆化搜索吧。。

    【代码】

    #include <bits/stdc++.h>
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define all(x) x.begin(),x.end()
    #define pb push_back
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    using namespace std;
    
    const double pi = acos(-1);
    const int dx[4] = {0,0,1,-1};
    const int dy[4] = {1,-1,0,0};
    
    int n,a,b,c;
    string s;
    map <pair<int,pair<int,int> >,int> dic;
    bool bo1 = false,bo2 = false,bo3 = false;
    
    void dfs(int a,int b,int c){
        pair<int,pair<int,int> > temp = make_pair(a,make_pair(b,c));
        if (dic[temp]) return;
        dic[temp]=1;
        if (a+b+c==1){
            if (a==1) bo1 = true;
            if (b==1) bo2 = true;
            if (c==1) bo3 = true;
            return;
        }
        if (a>0 && b>0) dfs(a-1,b-1,c+1);
        if (a>0 && c>0) dfs(a-1,b+1,c-1);
        if (b>0 && c>0) dfs(a+1,b-1,c-1);
        if (a>1) dfs(a-1,b,c);
        if (b>1) dfs(a,b-1,c);
        if (c>1) dfs(a,b,c-1);
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        cin >> n;
        cin >> s;
        for (int i = 0;i < (int) s.size();i++){
            if (s[i]=='B') a++;
            if (s[i]=='G') b++;
            if (s[i]=='R') c++;
        }
        dfs(a,b,c);
        if (bo1) cout<<'B';
        if (bo2) cout<<'G';
        if (bo3) cout<<'R';
    	return 0;
    }
    
    
  • 相关阅读:
    slice,substr和substring的区别
    http请求方法
    Git常用命令
    IOS开发之NSLog使用技巧
    网络请求之get与post异步请求
    通知(广播)传值
    [转]->ios推送:本地通知UILocalNotification
    [转]iOS 不要使用tag传递TableViewCell的indexPath值
    UIWebView uiwebview 加载本地html
    [转]字符串编码转换
  • 原文地址:https://www.cnblogs.com/AWCXV/p/9301684.html
Copyright © 2011-2022 走看看