UVA10817:Headmaster's Headache(状压dp)

UVA10817:Headmaster's Headache(状压dp)_第1张图片

题意:s个学科,每个学科至少要2个老师教,现有m个老师,不能辞退他们的前提下,从n个应聘者招收若干个使得每个学科至少2个老师教,求总工资的最小值。

思路:dp[i][j]中的i表示科目被选的状态,j表示多于1个人选择某科目的状态,dp[(1<

# include 
# define INF 0x3f3f3f3f
using namespace std;

int dp[1<<8][1<<8], sta[101], cost[101], num[10], sta1, sta2, sum, s, m, n, tmp;;

int solve()
{
    int up = (1<=0; --j)
            for(int k=up; k>=0; --k)
            {
                if(dp[j][k] == INF) continue;
                int nsta1 = (j|sta[i]);
                int nsta2 = (j&sta[i])|k;
                dp[nsta1][nsta2] = min(dp[nsta1][nsta2], dp[j][k] + cost[i]);
            }
    return dp[up][up];
}

int main()
{
    char str[100];
    while(~scanf("%d%d%d",&s,&m,&n)&&s)
    {
        memset(sta, 0, sizeof(sta));
        memset(cost, 0, sizeof(cost));
        memset(num, 0, sizeof(num));
        sta1 = sta2 = sum = 0;
        while(m--)
        {
            scanf("%d",&tmp);
            gets(str);
            int len = strlen(str);
            for(int i=0; i= 2)
                sta2 |= (1<





转载于:https://www.cnblogs.com/junior19/p/6729913.html

你可能感兴趣的:(UVA10817:Headmaster's Headache(状压dp))