UVA 10817 교장선생님의 고민(상압 DP+기억화 검색)

The headmaster of Spring Field School is considering employing some new teachers for certain subjects. There are a number of teachers applying for the posts. Each teacher is able to teach one or more subjects. The headmaster wants to select applicants so that each subject is taught by at least two 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 are numbered from 1 to S. You must keep on employing all of them. After that there are N lines, giving the details of the applicants in the same format. Input is terminated by a null case where S = 0. This case should not be processed. Output For each test case, give the minimum cost to employ the teachers under the constraints. Sample Input 2 2 2 10000 1 20000 2 30000 1 2 40000 1 2 0 0 0 Sample Output 60000
#include
#include
#include
#include//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include
#include
#include
#include
#include
#include
#define mod 1e9+7
#define ll unsigned long long
#define MAX 1000000000
#define ms memset
#define maxn 60005

#define INF 1000000

#define debug puts("YES");
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;

int n,m,k;
/*
    : m    k   ,               ,
                               。

    ,         (  ),
        ,             ,
s0:         ,s1:            ,s2:    2         。

               sta[i],           。
     s1 s2   ,s0      。

*/
int cost[130];
int sta[130];///
char c;

int d[130][1<<9][1<<9];
int dp(int i,int s0,int s1,int s2)///    
{
    if(i==m+k) return s2==(1<=0) return ans;
    ans=INF;
    if(i>=m) ans=min(ans,dp(i+1,s0,s1,s2));
    int m0=s0&sta[i],m1=s1&sta[i];
    s0^=m0,s1=(s1^m1)|m0,s2|=m1;
    ans=min(ans,cost[i]+dp(i+1,s0,s1,s2));
    return ans;
}

int main()
{
    while(scanf("%d%d%d",&n,&m,&k)&&(n||m||k))
    {
        for(int i=0;i='1') st+=1<

좋은 웹페이지 즐겨찾기