CSU 1548:design Road (three points)

Source: Internet
Author: User

Test instructions: Needs to be repaired from (0,0) point to (x, y)

Where there are n and y axes parallel to the river

Unit cost of road repairing C1 repair Bridge Unit Cost C2

Q What is the minimum total cost?

Idea: Merge all the rivers

The length of the bridge repeatedly

Find the minimum cost

#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <stdlib.h > #include <algorithm> #include <queue> #include <stack> #include <ctype.h>using namespace std;const int maxn=100+5;int vis[10000+100];int a[maxn];int cmp (int a,int b) {return a>b;}    int max (int a,int b) {if (a>b) return A; else return b;}    int main () {int kase;    scanf ("%d", &kase);        while (kase--) {int n,ans=0,cnt=0,res=0,maxn=0,minn,numa=0,numb=0,sum=0;        scanf ("%d", &n);            for (int i=0;i<n;i++) {int op,num;            scanf ("%d%d", &op,&num);            if (op==2) ans+=num;        if (op==1) {a[cnt++]=num;sum+=num;}           } if (cnt>0) {memset (vis,0,sizeof (VIS));           Vis[0]=1; for (int i=0;i<cnt;i++) {for (int j=10000;j>=a[i];j--) {if (V               Is[j-a[i]]==1) Vis[j]=1;     }      } int hsum= (sum+1)/2;           int l=hsum;//r=hsum;           while (vis[l]==0) {l--;        } maxn=max (L,sum-l);        } RES=ANS+MAXN;    printf ("%d\n", res); } return 0;}

  

CSU 1548:design Road (three points)

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.