UVA 108,171 headmaster ' s headache

Source: Internet
Author: User

Headmaster ' s headache

Time Limit: 3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu

SubmitStatusPracticeUVA 10817
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 Const intinf=1e9+7;6 Const intmm=65536;7 8 intdp[ the][65590];9 intappcost[ the],appnum[ the][ -];Ten  One intMain () A { -     ints,n,m,x,y; -     inti,j,k; the     intsum0,k0; -     Chara[103]; -      while(SCANF (" %d%d%d", &s,&m,&n)! =EOF) -     { +         if(s==0) -              Break; +memset (Appnum,0,sizeof(Appnum)); A          atsum0=0; k0=0; -          for(i=1; i<=m;i++) -         { -scanf"%d",&x); -sum0=sum0+x; - gets (a); in              for(j=0; a[j]!=' /'; j + +) -             { to                 if('1'&LT;=A[J] && a[j]<='9') +                 { -y=a[j]-'0'; y--; the                     if(! ((K0>> (2*y)) &1)) *                     { $K0=k0 | (1<< (2*y));Panax Notoginseng                     } -                     Else if(! ((K0>> (2*y+1)) &1)) the                     { +K0=k0 | (1<< (2*y+1)); A                     } the                 } +             } -         } $          for(i=1; i<=n;i++) $         { -scanf"%d",&appcost[i]); - gets (a); the             intnum=0; -              for(j=0; a[j]!=' /'; j + +)Wuyi             { the                 if('1'&LT;=A[J] && a[j]<='9') -                 { Wu                     //y=a[j]-' 0 '; y--; -num++; Aboutappnum[i][num]=a[j]-'0'; $                 } -             } -appnum[i][0]=num; -         } A  +         ints=1<< (2*s); the          for(i=0; i<s;i++) -         { $dp[0][i]=inf; the         } thedp[0][k0]=SUM0; the  the          for(i=1; i<=n;i++) -         { in              for(j=0; j<s;j++) the             { thedp[i][j]=dp[i-1][j]; About             } the  the              for(j=0; j<s;j++) the             { +                 if(dp[i-1][j]<inf) -                 { thek=J;Bayi                      for(intL=1; l<=appnum[i][0];l++) the                     { they=appnum[i][l]-1; -                         if(! ((K>> (2*y)) &1)) -                         { theK=k | (1<< (2*y)); the                         } the                         Else if(! ((K>> (2*y+1)) &1)) the                         { -K=k | (1<< (2*y+1)); the                         } the                     } theDp[i][k]=min (dp[i][k],dp[i-1][j]+appcost[i]);94                 } the             } the         } theprintf"%d\n", dp[n][(1<< (2*s))-1]);98     } About     return 0; -}
View Code

UVA 108,171 headmaster ' s headache

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.