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'<=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'<=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