zoukankan      html  css  js  c++  java
  • hdu 4620 搜索

    好苦逼,为啥数组开小了,不会runtime error,还得我WA了几个小时,我泪流满面。

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4620

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<vector>
    using namespace std;
    
    const int maxn = 35;
    
    struct Cut{
        int T;
        int icnt;
        int bef_id;
        int a[11];
        bool operator < (const Cut& r) const{
            return T < r.T;
        }
    }cut[maxn];
    int N,M,W;
    bool vis[400];
    int ans[maxn],temp[maxn];
    int anspv;
    
    void dfs(int now,int fa_time,int deep){  // printf("now,fa_time,deep   %d %d %d
    ",now,fa_time,deep);
        if(deep > anspv){
            anspv = deep;
            copy(temp,temp+anspv,ans);
            //for(int i=0;i<anspv;i++) printf("%d ",ans[i]);  printf("
    ");
        }
        if(now >= N) return;
    
        if(deep + N-now <= anspv)   return;
    
        for(int i=now;i<N;i++){
            if(cut[i].T - fa_time > W && fa_time != -1) continue;
            int sta[11],cnt =0;
            for(int j=0;j<cut[i].icnt;j++){
                if(!vis[cut[i].a[j]])
                    sta[cnt++] = cut[i].a[j];
            }
            if(cnt < 3) continue;
            for(int j=0;j<cnt;j++)
                vis[sta[j]] = true;
    
            temp[deep] = cut[i].bef_id;
            dfs(i+1,cut[i].T,deep+1);
    
            for(int j=0;j<cnt;j++)
                vis[sta[j]] = false;
        }
    }
    int main()
    {
       //freopen("E:\acm\input.txt","r",stdin);
        int T;
        cin>>T;
        while(T--){
            cin>>N>>M>>W;
            int pv = 0;
            for(int i=1;i<=N;i++){
                int c,time;
                scanf("%d %d",&c,&time);
                if(c<3) continue;
                cut[pv].icnt = c;
                cut[pv].bef_id = i;
                cut[pv].T = time;
                for(int i=0;i<c;i++)
                    scanf("%d",&cut[pv].a[i]);
                pv++;
            }
            N = pv;
            sort(cut,cut+N);
    
            anspv = 0;
            memset(vis,0,sizeof(vis));
            dfs(0,-1,0);
           sort(ans,ans+anspv);
            printf("%d
    ",anspv);
            for(int i=0;i<anspv-1;i++){
                printf("%d ",ans[i]);
            }
            printf("%d
    ",ans[anspv-1]);
        }
    }
    View Code
  • 相关阅读:
    [PTA练习] 愿天下有情人都是失散多年的兄妹(25分)
    sql server远程连接非1433端口
    java把double转化为long型
    StringUtils工具类
    JfreeChart折线图
    Log4j配置
    Ibatis,Spring整合(注解方式注入)
    Spring中的autowire属性(转)
    MyBatis3入门样例
    struts2 ibatis Spring系统架构图
  • 原文地址:https://www.cnblogs.com/acmdeweilai/p/3292424.html
Copyright © 2011-2022 走看看