zoukankan      html  css  js  c++  java
  • XTUOJ 1248 TC or CF 搜索

    这个题一眼看上去不会

    然后有人说是网络流

    然后我就想怎么建图啊,然后不会(是本蒟蒻太垃圾了),肯定有网络流解法

    然后去群里问了gdut的巨巨,他说他队友爆搜+剪枝过了(我也是非常的叹服)

    然后我也写了一个2^50的搜索剪枝,居然真过了(不知道是数据弱还是大力出奇迹)

    #include <cstdio>
    #include <iostream>
    #include <ctime>
    #include <vector>
    #include <cmath>
    #include <map>
    #include <queue>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    typedef long long LL;
    const int N=1e5+5;
    const int INF=0x3f3f3f3f;
    const int mod=1e9+7;
    vector<int>g[55],v[55],op[55];
    int belong[55],ret,n,m;
    void dfs(int pos,int c,int t1,int t2){
      if(t1>n-3||t2>n-3)return; 
      if(c>=ret)return;
      if(n==pos){
        if(t2+1>n-3)return;
        for(int i=0;i<g[n].size();++i){
          if(op[n][i]==2&&belong[g[n][i]]==1)c+=v[n][i];
        }
        ret=min(ret,c);
        return;
      }
      belong[pos]=1;
      int tmp=0;
      for(int i=0;i<g[pos].size();++i){
        if(op[pos][i]==1&&belong[g[pos][i]]==2)tmp+=v[pos][i];
      }
      dfs(pos+1,c+tmp,t1+1,t2);
      belong[pos]=2;
      for(int i=0;i<g[pos].size();++i){
        if(op[pos][i]==2&&belong[g[pos][i]]==1)c+=v[pos][i];
      }
      dfs(pos+1,c,t1,t2+1);
    }
    int main()
    {
        while(~scanf("%d%d",&n,&m)){
          for(int i=1;i<=n;++i){
            v[i].clear();
            g[i].clear();
            op[i].clear();
          }
          for(int i=1;i<=m;++i){
            int k1,k2,k3;
            scanf("%d%d%d",&k1,&k2,&k3);
             if(k1>k2){
              v[k1].push_back(k3);
              g[k1].push_back(k2);
              op[k1].push_back(1);
             }
             else{
              v[k2].push_back(k3);
              g[k2].push_back(k1);
              op[k2].push_back(2);
             }
          }
          ret=INF;
          belong[1]=1;
          dfs(2,0,1,0);
          printf("%d
    ",ret);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    小白的Python之路_day1
    Vue---tab切换时不刷新
    Vue---第十五章使用VScode编写第一个脚本
    Vue---第十四章visual studio code使用
    Vue---第十三章基础运算和v-model
    Vue---第十二章批量下载模块
    vue---第十一章全局依赖环境区分
    Vue---第十章全局变量
    Vue---第九章NPM
    hadoop-Rpc使用实例
  • 原文地址:https://www.cnblogs.com/shuguangzw/p/5596913.html
Copyright © 2011-2022 走看看