Server Load balancer 10817-Headmaster's Headache (status compression DP)

Source: Internet
Author: User

Server Load balancer 10817-Headmaster's Headache (status compression DP)

There are S (S <= 8) courses, each course requires at least two teachers to teach, it takes a certain amount of money to hire each teacher, each teacher can teach one or more courses. Existing M (M <= 20) in-service teachers, N (N <= 100) candidates, for in-service teachers, each must be hired, what is the minimum cost if at least two instructors are required for each course.


D [I] [j] indicates the minimum cost when the status of the former I teacher is j. j indicates the number of S-bits in triplicate, if the value is 0, the course u is taught by no teacher. If the value is 1, the course u is taught by one teacher. If the value is 2, the course u is taught by two teachers. The final answer is d [N] [3 ^ S-1].

When calculating d [I] [j], consider whether to hire the I-th teacher to complete the status transfer. If hired, try to make full use of the Course taught by this teacher, for each course taught by this teacher, if the current j course corresponds to a three-digit number greater than 0, then minus 1, otherwise it will not change.


State transition equation: d [I] [j] = max {d [I-1] [j], d [I-1] [v] + cost [I]} (v is the State after subtracting the course that can be subtracted)


#include
 
  #include
  
   #include
   
    char a[300];int b[105][10];int c[10];int d[105][7300];int co[105];int basethre[7100][10];int basetco[10];int main(void){int i,j,u,m,n,p,q,lo,sum,sump,minp,OK;q=1;for(i=1;i<=8;i++){basetco[i]=q;q=q*3;}for(i=0;i
    
     ='0')&&(a[j]<='9')){sump=0;while((a[j]>='0')&&(a[j]<='9')){sump=sump*10+a[j]-'0';j++;}sum=sum+sump;break;}}for(u=j;u
     
      ='0')&&(a[u]<='9')&&(c[a[u]-'0']<2)){c[a[u]-'0']++;}}}for(i=1;i<=m;i++){gets(a);lo=strlen(a);for(j=0;j
      
       ='0')&&(a[j]<='9')){sump=0;while((a[j]>='0')&&(a[j]<='9')){sump=sump*10+a[j]-'0';j++;}co[i]=sump;break;}}for(u=j;u
       
        ='0')&&(a[u]<='9')){b[i][a[u]-'0']=1;}}}d[0][0]=sum;for(j=1;j<=q;j++){OK=1;for(u=1;u<=p;u++){if(basethre[j][u]>c[u]){OK=0;break;}}if(OK==1){d[0][j]=sum;}else{d[0][j]=1000000000;}}for(i=1;i<=m;i++){d[i][0]=sum;for(j=1;j<=q;j++){minp=d[i-1][j];sump=0;for(u=1;u<=p;u++){if((basethre[j][u]>0)&&(b[i][u]==1)){sump=sump+basetco[u];}}if(minp>d[i-1][j-sump]+co[i]){minp=d[i-1][j-sump]+co[i];}d[i][j]=minp;}}printf("%d\n",d[m][q]);for(i=0;i<=10;i++){c[i]=0;}memset(b,0,sizeof(b));scanf("%d%d%d",&p,&n,&m);getchar();}return 0;}
       
      
     
    
   
  
 


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.