• uva 103 经典DAG变形


    https://vjudge.net/problem/UVA-103

        也是一个经典的DAG模型,因为书上的翻译和原文不照导致WA两发= =

        对于同一维度的两个箱子A,B,A可以嵌套在B中的一个充分条件是A所有的边长和 < B所有的边长和,先根据边长和进行排序,在比较A是否能嵌套于B中时,把两个箱子的边长按升序排列后一一对比只要均满足A<B就说明A可以嵌套与B中。

      

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int V,N,f[35];
     4 struct box
     5 {
     6     int s,u;
     7     int a[11];
     8     void show()
     9     {
    10         for(int i=1;i<=V;++i) printf("%d ",a[i]);puts("");
    11     }
    12 }P[35];
    13 bool cmp(box A,box B){return A.s<B.s;}
    14 bool ok(box A,box B)
    15 {
    16     for(int i=1;i<=V;++i)
    17         if(A.a[i]>=B.a[i]) return 0;
    18     return 1;
    19 }
    20 int main()
    21 {
    22     int i,j,k;
    23     int path[35];
    24     while(cin>>N>>V){int ans=0;
    25     memset(path,-1,sizeof(path));
    26         for(i=1;i<=N;++i)
    27         {
    28             P[i].s=0;
    29             P[i].u=i;
    30             for(j=1;j<=V;++j)
    31             {
    32                 scanf("%d",&P[i].a[j]);
    33                 P[i].s+=P[i].a[j];
    34             }
    35             sort(P[i].a+1,P[i].a+1+V);
    36         }
    37         memset(f,0,sizeof(f));
    38         sort(P+1,P+1+N,cmp);
    39         for(i=1;i<=N;++i)
    40         {
    41             int maxn=0,u=i;
    42             for(j=1;j<i;++j)
    43             {
    44                 if(ok(P[j],P[i])&&f[j]>maxn){
    45                     maxn=f[j];
    46                     u=j;
    47                 }
    48             }
    49             path[i]=u;
    50             f[i]=maxn+1;
    51             ans=max(ans,f[i]);
    52         }
    53         stack<int>T;
    54         int x=ans;
    55         for(i=N;i;--i)
    56         {
    57             if(f[i]==ans){
    58                 int u=i;
    59             while(T.empty()||u!=T.top()){
    60                 T.push(u);
    61                 u=path[u];
    62             }
    63                 break;
    64             }
    65         }
    66         printf("%d
    %d",ans,P[T.top()].u);T.pop();
    67         while(!T.empty()){
    68             printf(" %d",P[T.top()].u);
    69             T.pop();
    70         }
    71         puts("");
    72     }
    73     return 0;
    74 }
  • 相关阅读:
    KindEditor自动过滤首行缩进和全角空格的解决方法
    网站流量、连接数等监控
    VSFTP的使用
    CentOs 设置静态IP
    MySQL 5.7版本sql_mode=only_full_group_by问题
    使用密钥登录CentOS系统(基于密钥的认证)
    FIRMWARE BUG – THE BIOS HAS CORRUPTED HW-PMU RESOURCES
    Ubuntu上的MySQL可以远程访问
    自动生成单据编号
    SQL Server 重置SA密码语句
  • 原文地址:https://www.cnblogs.com/zzqc/p/7490178.html
Copyright © 2020-2023  润新知