Algorithm: UVA 10817

Source: Internet
Author: User
Tags min

The main effect of the topic

There are n teachers and m job seekers in a school, a known salary and a collection of teaching courses, and a minimum wage is required to teach at least two teachers per course. Serving teachers must be recruited.

Ideas

This question is not very good to think, has been engaged for a long time.

F[S1][S2]: S1 indicates that the course collection {S1} has at least one teacher teaching situation.

S2 says there are at least two teachers taught in the course collection {s2}.

The pi of each job seeker, for each job seeker, either chooses, or does not choose, is 01 knapsack question.

For S1,S2, you can launch the next status based on the currently enumerated job Seekers course:

nextS1 = P[i] | S1,

NextS2 = (P[i] & S1) | S2

F[NEXTS1] [nextS2] = min (f[nexts1][nexts2], F[S1][S2] + p[i])

Code

/**========================================== * is a solution for ACM/ICPC problem * * @problem: UVA 10817-hea Dmaster ' s headache * @type: DP * @author: Shuangde * @blog: blog.csdn.net/shuangde800 * @email: zengshuangde@gmail.com *== =========================================*/#include <iostream> #include <cstdio> #include <algorithm
    
> #include <vector> #include <queue> #include <cmath> #include <cstring> using namespace std;
typedef long long Int64;
const int INF = 0X3F3F3F3F;
    
Const double PI = ACOs (-1.0);
    
    
const int MAXN = 150;
int Coursenum, M, N, sum;
int maxstate;
int f[1<<8][1<<8];
    
    
int P[MAXN], C[MAXN], cnt[10]; int dp (int st1, int st2) {memset (f, 0x3f, sizeof (f)); f[st1][st2] = sum; for (int i=m+1; i<=n+m; ++i) {for (int s1=maxsta Te s1>=0; --S1) {for (int s2=maxstate; s2>=0;--s2) {if (F[S1][S2) >= INF) continue; int st1 = (P[I]|S1); int st2 = (p[i]&s1 ) |
S2; F[st1][st2] = min (F[ST1][ST2], f[s1][s2]+c[i]);
}} return f[maxstate][maxstate]; int main () {char str[1000]; while (~SCANF ("%d%d%d", &coursenum, &m, &n) && coursenum) {Maxs
    
Tate = (1<<coursenum)-1;
sum = 0;
    
int st1=0, st2=0;
    
memset (CNT, 0, sizeof (CNT));
    
for (int i=1; i<=m+n; ++i) {scanf ("%d", &c[i]); gets (str);
P[i] = 0; for (int j=0; J<strlen (str); ++j) {if (IsDigit (str[j)) {int num = str[j]-' 0 '; P[i] |= 1<< (num-1); if (I <= m)
++CNT[NUM-1];
    
} if (I <= m) {sum = C[i]; st1 |= p[i];}
    
for (int i=0; i<coursenum; ++i) if (Cnt[i] > 1) st2 |= (1<<i);
    
printf ("%d\n", DP (ST1, ST2));
return 0; }

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.