UVA 10817 headmaster ' s headache pressure DP

Source: Internet
Author: User


Record two states S1,S2 which courses were taught by 1 or 2 people, and then memorized the search


UVA-10817

Headmaster ' s headache
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

Description

Problem D:headmaster ' s headache

time limit:2 seconds

THe headmaster of Spring Field School is considering employing some new teachers for certain subjects. There is a number of teachers applying for the posts. Each teacher are able to teach one or more subjects. The headmaster wants to select applicants so it each subject are taught by at least-teachers, and the overall cost is Minimized.

Input

The input consists of several test cases. The format of each of them is explained below:

the first line contains three positive integers  S ,   M  and  N .   S   (≤8) is the number of subjects,  M   (≤20) is the number of serving Teachers, and  N   (≤100) is the number of applicants.

Each of the following M Lines describes a serving teacher. It first gives the cost of employing him/her (10000≤ C ≤50000), followed by a list of subjects that he/she can Teach. The subjects is numbered from 1 to S. You must keep on employing all of them. After that there is N lines, giving the details of the applicants in the same format.

Input is terminated by a null case where S = 0. This case is should not being processed.

Output

For each test case, give the minimum cost to employ the teachers under the constraints.

Sample Input
2 2 210000 120000 230000 1 240000 1 20 0 0

Sample Output
60000

Problemsetter:mak Yan Kei
Idea from "Linear Optimization in Applications", S. L. Tang, Hong Kong University Press, 1999

Source

Root:: AOAPC i:beginning algorithm Contests (Rujia Liu):: Volume 5. Dynamic programming
Root:: AOAPC i:beginning Algorithm Contests--Training Guide (Rujia Liu):: Chapter 1. Algorithm Design:: Dynamic Programming:: Exercises:beginner
Root:: Prominent problemsetters:: Mak Yan Kei
Root:: AOAPC ii:beginning algorithm Contests (Second Edition) (Rujia Liu):: Chapter 9. Dynamic Programming:: Examples
Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: More advanced Topics:: More advanced DP Techniques:: DP Level 3
Root:: Competitive programming 2:this increases the lower bound of programming contests. Again (Steven & Felix Halim):: More advanced Topics:: More advanced Dynamic Programming:: DP + Bitmask

Submit Status



/* ***********************************************author:ckbosscreated time:2015 February 23 Monday 19:38 07 seconds file Name : uva10817.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;const int maxn=150;int s,n,m;struct teacher{int Val,cos;} Teacher[maxn];int dp[maxn][260][260];int goal;void init () {memset (teacher,0,sizeof (teacher)); Memset (Dp,-1,sizeof ( DP)); goal= (1<<s)-1;} void Dfs (int p,int s1,int s2) {if (dp[p][s1][s2]!=-1) return, if (s1==goal&&s2==goal) {dp[p][s1][s2]=0; return;} if (p+1>n+m) {dp[p][s1][s2]=1e9; return;} int np=p+1;int cost=teacher[np].val;int num=teacher[np].cos;int cf=num&s1;int ns1=s1|num;int Ns2=s2|cf;dfs (NP, NS1,NS2);//Emplore DFS (NP,S1,S2);//Unemploredp[p][s1][s2]=min (DP[NP][NS1][NS2]+COST,DP[NP][S1][S2]);}    int main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), while (scanf ("%d%d%d", &s,&m,&n)!=eof&&s&&n& &m) {init (); int Sum1=0;getchar (); for (int i=0;i<m+n;i++) {char str[1000];gets (str); int Sz=strlen (str); bool First=true;int temp=0,num=0,val=0;for (int j=0;j<sz;j++) {if (str[j]>= ' 0 ' &&str[j]<= ' 9 ') {temp=temp* 10+str[j]-' 0 '; }if (str[j]== "| | J==SZ-1) {if (first) {val=temp; first=false;} else {temp--; num|= (1<<temp);} Temp=0;}} if (i<m) {sum1+=val; val=0;} teacher[i+1]= (Teacher) {val,num};}        DFS (0,0,0);p rintf ("%d\n", DP[0][0][0]+SUM1);} return 0;}


UVA 10817 headmaster ' s headache pressure DP

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.