hdoj ZZY’s Dilemma 4152 (DP) 好题

原创 2015年11月20日 21:39:21

ZZY’s Dilemma

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 612    Accepted Submission(s): 258


Problem Description
ZZY has many habits like seeing movie, listening music, playing PC game and football and so on. Besides he has many goals, as not every habit is good for achieving his goals, he falls into the dilemma of making a choice between his goals and habits.
Now ,we define the effect that one habit has on each goal is represented as a vector,and the elements of the vector are integers,ex.vector(100,90,-10,80)means it has 100 point effect on goal 1,90 point effect on goal 2,-10 point effect on goal 3 and 80 point effect on goal 4(the positive point means good effect and the negative point means bad effect),and the given requirement of each goal is represented as integer.please help ZZY to achieve his goals as well as keeps his habits as many as possible.

Input
There are multi cases , read the data until EOF.( No more than 10 cases )
Line 1: The number of ZZY’s goals N(0<N<=20)
Line 2: The requirement of each goals (0 < w <= 1000)
Line 3: The number of ZZY’s habits M(0 < M <= 16)
Line 4-M+4: Each line contains N integers, the ith integer represents the effect on ith goal (-1000 <= data <= 1000).

Output
For each case: The output is a single line that contains:
* the maximum number of habits ZZY can keep, followed by:
* a SORTED list (from smallest to largest) of the habit ZZY can keep. If more than one set of habits could meet the requirement, choose the set with the smallest habit numbers.
Just please output 0 if there is no way to achieve ZZY’s goals.

Sample Input
4 100 200 300 400 3 100 100 400 500 100 -10 50 300 100 100 -50 -50
Sample Output
2 1 3
#include<stdio.h>
#include<string.h>
int a[22];
int b[22][22];
int c[22];
int main()
{
    int n,m,a1,a2;
    int i,j,k;
    while(scanf("%d",&n)!=EOF)
    {
        a1=-1;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        scanf("%d",&m);
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                scanf("%d",&b[i][j]);
            }
        }
        for(i=1;i<(1<<m);i++)
        {
            memset(c,0,sizeof(c));
            int num=0;
            for(j=0;j<m;j++)
            {
                if(i&(1<<j))
                {
                    num++;
                    for(k=0;k<n;k++)
                        c[k]+=b[j][k];
                }
            }
            int kk;
            for(kk=0;kk<n;kk++)
                if(c[kk]<a[kk])
                    break;
            if(kk>=n)
            {
                if(num>a1)
                {
                    a1=num;
                    a2=i;
                }
                else if(num==a1&&a2>i)
                {
                    a1=num;
                    a2=i;
                }
            }
                
        }
        if(a1==-1)
            printf("0\n");
        else
        {
            printf("%d",a1);
            for(i=0;i<n;i++)
            {
                if(a2&(1<<i))
                    printf(" %d",i+1);
            }
            printf("\n");
        }
    }
    return 0;
}


hdu 4152 ZZY’s Dilemma【DFS】

ZZY’s Dilemma Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To...

HDU 4152 ZZYs Dilemma(枚举 or dfs)

ZZY’s Dilemma Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To...

UVa Problem 701 The Archeologist’s Dilemma (考古学家的烦恼)

// The Archeologist’s Dilemma (考古学家的烦恼) // PC/UVa IDs: 110503/701, Popularity: A, Success rate: low ...

BZOJ 4152 状压DP 解题报告

4152: [AMPPZ2014]The CaptainTime Limit:给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号...

[刷题]算法竞赛入门经典(第2版) 6-14UVa12118 - Inspector's Dilemma

DesicriptionIn a country, there are a number of cities. Each pair of city is connected by a highway,...

[YY题]HDOJ5288 OO’s Sequence

转载: 题意:求这个式子的值就是对每个区间[i, j]枚举区间中的每个数ai到aj, 判断这个a是否对[i, j]这个区间内所有数取模都不等于0, 若是,则这个区间满足条件问有多少个满足条件的区间 ...

hdoj 龟兔赛跑 2059 (DP) 好题

龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub...

hdoj 吉哥系列故事——完美队形I 4512 (LICS&dp)单调增回文数列长度 好题

吉哥系列故事——完美队形I Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hdoj ZZY’s Dilemma 4152 (DP) 好题
举报原因:
原因补充:

(最多只允许输入30个字)