05: One of the Cows in the Cave Cows 1 Cave, cavecows

Source: Internet
Author: User

05: One of the Cows in the Cave Cows 1 Cave, cavecows

Total time limit:
10000 ms
 
Time limit for a single test point:
1000 ms
 
Memory limit:
262144kB
Description
Few people know that cows really like exploring in caves. There are N (1 ≤ N ≤ 100) chambers in the cave, connected by M (1 ≤ M ≤ 1000) bidirectional channels. each pair of Chambers has at most one bidirectional channel. there are K (1 ≤ K ≤ 14) Chambers with 1 bundle of hay in them. when a cow eats 1 bundle of hay, its weight index increases by 1. the greedy bid wants to explore in the cave. she wanted to eat as much hay as possible, but each channel had a width threshold. If the body mass index exceeded the threshold, Bessie would be stuck and wish her to start from cave 1, the body mass index is 0. after walking around in the cave, she will return to the cave 1. how many bundles of hay can she eat at most? Note: Bessie does not have to eat hay in a cave.

 

Input
Input N, M, K in the first row, followed by an integer in each line in the next K lines, indicating that there is a bundle of hay in this cave; then there are three integers in each line in the next M line, it indicates the start and end points of a two-way channel and the width threshold.
Output
The maximum number of hay that can be eaten.
Sample Input
6 7 5123451 2 33 6 26 2 102 4 15 1 14 5 11 6 1
Sample output
4
Source
USACO 2004 Open Orange
Idea: greedy. Sort the threshold values of each straw in order.
Pay attention to the following details:
1. I want to determine whether the No. 1 cave has a region.
2. Finally Write>
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 const int MAXN=4001; 8 const int maxn=0x3f; 9 void read(int &n)10 {11     char c='+';int x=0;bool flag=0;12     while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}13     while(c>='0'&&c<='9')14     x=(x<<1)+(x<<3)+c-48,c=getchar();15     flag==1?n=-x:n=x;16 }17 int n,m,k;18 struct node19 {20     int have;21     int need;22     int pos;23 }a[MAXN];24 int map[MAXN][MAXN];25 int dis[MAXN][MAXN];26 int comp(const node &a,const node &b)27 {28     if(a.have==b.have)29         return a.need<b.need;30     else31         return a.have>b.have;32 }33 int main()34 {35     read(n);read(m);read(k);36     int num=k;37     for(int i=1;i<=k;i++)38     {39         int p;40         read(p);41         a[p].have=1;42         a[i].pos=i;43     }44     memset(map,maxn,sizeof(map));45     for(int i=1;i<=m;i++)46     {47         int x,y,z;48         read(x);read(y);read(z);49         map[x][y]=z;50         map[y][x]=z;51     }52     53     for(int i=1;i<=n;i++)54         map[i][i]=0;55     56     for(int k=1;k<=n;k++)57         for(int i=1;i<=n;i++)58             for(int j=1;j<=n;j++)59                 if(map[i][j]<maxn)60                     map[i][j]=max(map[i][j],min(map[i][k],map[k][j]));61                 else 62                     map[i][j]=min(map[i][k],map[k][j]);63     64     for(int i=1;i<=n;i++)65         if(a[i].have)66             a[i].need=map[1][i];67     68     69     sort(a+1,a+n+1,comp);70     71     int now=0;72     int flag=0;73     for(int i=1;i<=num;i++)74     {75     //    if(a[i].have==0)break;76         if(a[i].have&&a[i].pos==1)77         {78             flag=1;79             continue;80         }81         if(a[i].need>now)82             now++;83     84     }85     if(flag==1)86         now++;87     printf("%d",now);88     return 0;89 } 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.