zoukankan      html  css  js  c++  java
  • 1314: ZZY的困惑

    1314: ZZY的困惑

    Time Limit: 2 Sec  Memory Limit: 128 M
    [Submit][Status][Web Board]

    Description

     ZZY有很多爱好~~比如足球、电影、三国杀、A题,而他希望在这些爱好中能收获一些东西~~但是并不是所有爱好对所有目标都是起积极作用的..ZZY十分的困惑..于是列了下自己想获得的收获并且给每个目标设立了最小要达到的权值...并且给自己的爱好对每个收获目标进行了评值..这个值若是负则代表不利于获得某个收获~~为0代表没影响~~为正的代表利于获得某种收获..现在ZZY已经制作好了这些数据想请你帮帮忙~~在保证所有的目标最低要求都能达成的情况下保留尽量多的爱好~~

    Input

     多组数据读到EOF结束(不超过10组)每组数据
       第一行为ZZY的收获目标个数N ( 0<N<=20 ) 
       第二行为ZZY对每个目标所订的一个最低权值 ( 0 < w <= 1000 )
       第三行为ZYY的爱好总数M ( 0 < M <= 16 )
       下面的M行每行有N个数代表每个爱好对每个目标的促进权值..( -1000 <= k <= 1000 )

    Output

    每组输入对应一行输出:
       第一个数为能保留的最多爱好个数..紧接着为这些爱好分别对应输入的是那几个序号..
       若有多种都能达到保留个数请输出相对来说较小的(如 1 2 与 3 4 同时能满足要求,那么选1 2)
       若怎么都无法实现目标那只能说着所有爱好都要不得,输出0...

    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 <iostream>
    #include <stdio.h>
    #include <queue>
    #include <stdio.h>
    #include <string.h>
    #include <vector>
    #include <queue>
    #include <set>
    #include <algorithm>
    #include <map>
    #include <math.h>
    #define Max(a,b) ((a)>(b)?(a):(b))
    using namespace std ;
    typedef long long LL ;
    int N  ,M ;
    bool Select[18] ;
    int num[18][21]  ;
    int dp[21] ;
    int object[21] ;
    int select_num ;
    vector<int>ans ;
    int judge(){
       for(int i=1;i<=N;i++){
           if(dp[i]<object[i])
               return  0 ;
       }
       return 1 ;
    }
    void dfs(int id){
        if(id==M+1){
            int select_now_num=0 ;
            memset(dp,0,sizeof(dp)) ;
            for(int i=1;i<=M;i++){
                 if(Select[i]){
                    select_now_num++ ;
                    for(int j=1;j<=N;j++)
                        dp[j]+=num[i][j] ;
                 }
            }
            if(judge()){
                 if(select_now_num>select_num){
                      select_num=select_now_num ;
                      ans.clear() ;
                      for(int i=1;i<=M;i++){
                           if(Select[i])
                               ans.push_back(i) ;
                      }
                 }
                 else if(select_now_num==select_num){
                       select_num=select_now_num ;
                       vector<int>temp ;
                       temp.clear() ;
                       for(int i=1;i<=M;i++){
                           if(Select[i])
                                temp.push_back(i) ;
                       }
                       int flag=0  ;
                       for(int i=0;i<ans.size();i++){
                           if(ans[i]>temp[i]){
                               flag=1 ;
                               break ;
                            }
                       }
                       if(flag){
                           ans.clear() ;
                           for(int i=0;i<temp.size();i++)
                               ans.push_back(temp[i]) ;
                       }
                 }
            }
            return  ;
        }
        Select[id]=0 ;
        dfs(id+1) ;
        Select[id]=1 ;
        dfs(id+1) ;
    }
    int main(){
       while(scanf("%d",&N)!=EOF){
           for(int i=1;i<=N;i++)
               scanf("%d",&object[i]) ;
           scanf("%d",&M) ;
           for(int i=1;i<=M;i++)
              for(int j=1;j<=N;j++)
                 scanf("%d",&num[i][j])  ;
           memset(Select,0,sizeof(Select))  ;
           select_num=0 ;
           dfs(1) ;
           printf("%d",select_num) ;
           if(select_num){
              for(int i=0;i<ans.size();i++)
                   printf(" %d",ans[i]) ;
           }
           puts("") ;
       }
       return 0 ;
    }
    

      

  • 相关阅读:
    SQL序列键
    SQL日期跟时间值序列
    springboot日志配置
    weblogic10补丁升级与卸载
    idea使用svn报错
    mybatis插入数据并返回主键(oracle)
    UTF-8格式txt文件读取字节前三位问题
    https连接器
    git将本地项目上传码云
    aop的使用
  • 原文地址:https://www.cnblogs.com/liyangtianmen/p/3352896.html
Copyright © 2011-2022 走看看