Usaco-2.1-holstein-pass

Source: Internet
Author: User

This kind of problem has never been encountered before. After nearly one day, it is easy to understand. This source program is exquisite:

/*ID: qq104801LANG: C++TASK: holstein*/#include <iostream>#include <fstream>#include <string>#include <vector>#include <cstdio>using namespace std;#define VMAX 25#define GMAX 15int v,g;vector<int>need;int feeds[GMAX][VMAX]={0};bool selected[GMAX]={false};int least=16;vector<int> result;bool check(){    int needs[VMAX]={0};    int sum=0;    for(int m=0;m<g;m++)        if(selected[m])sum++;        if(sum>=least)return false;    for(int i=0;i<v;i++)        for(int j=0;j<g;j++)            if(selected[j])needs[i] += feeds[j][i];                for(int k=0;k<v;k++)        if(needs[k] < need[k])return false;        return true;}void update(){    result.clear();    int sum=0;    for(int i=0;i<g;i++)        if(selected[i])        {            sum++;            result.push_back(i+1);        }        least=sum;}void dfs(int deep){        if(deep >= g)return;    selected[deep]=true;    if(check()) update();    else dfs(deep+1);    selected[deep]=false;    if(check()) update();    else dfs(deep+1);    return;}void test(){        freopen("holstein.in","r",stdin);    freopen("holstein.out","w",stdout);    cin>>v;    int i,j,temp;    for(i=0;i<v;i++)    {        cin>>temp;        need.push_back(temp);    }    cin>>g;    for(i=0;i<g;i++)        for(j=0;j<v;j++)        {            cin>>temp;            feeds[i][j]=temp;                    }        dfs(0);         cout<<least;    vector<int>::iterator it;    for(it=result.begin();it!=result.end();it++)        cout<<" "<<*it;        cout<<endl;}int main () {            test();            return 0;}

Test data:

USER: cn tom [qq104801]TASK: holsteinLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.008 secs, 3512 KB]   Test 2: TEST OK [0.003 secs, 3512 KB]   Test 3: TEST OK [0.014 secs, 3512 KB]   Test 4: TEST OK [0.003 secs, 3512 KB]   Test 5: TEST OK [0.003 secs, 3512 KB]   Test 6: TEST OK [0.003 secs, 3512 KB]   Test 7: TEST OK [0.005 secs, 3512 KB]   Test 8: TEST OK [0.014 secs, 3512 KB]   Test 9: TEST OK [0.014 secs, 3512 KB]   Test 10: TEST OK [0.076 secs, 3512 KB]All tests OK.Your program (‘holstein‘) produced all correct answers! This is your submission #3 for this problem. Congratulations!Here are the test data inputs:------- test 1 ----150150------- test 2 ----3100 200 300399 199 2992 2 21000 1000 1000------- test 3 ----41 1 1 141 1 0 01 0 1 00 1 0 10 0 0 1------- test 4 ----510 20 30 40 50510 10 10 10 100 10 10 10 100 0 10 10 100 0 0 10 100 0 0 0 10------- test 5 ----810 10 10 10 10 10 10 1071 1 1 1 1 1 1 12 2 2 2 2 2 2 23 3 3 3 3 3 3 34 4 4 4 4 4 4 4100 100 100 100 100 100 0 05 5 5 5 5 5 10 05 5 5 5 5 5 0 10------- test 6 ----5163 221 146 425 5091098 69 68 18 129132 185 196 64 17640 70 57 9 11573 189 145 87 11745 114 45 0 18137 137 174 73 17848 143 33 142 19233 107 148 2 15832 42 153 90 41165 81 156 7 121------- test 7 ----15335 425 380 283 513 140 360 349 505 187 358 309 485 495 19010123 137 194 60 137 89 153 122 115 198 47 76 38 62 11231 105 1 155 93 25 74 15 177 191 146 32 47 115 7116 72 139 64 112 39 173 33 61 118 119 136 32 132 10037 143 7 159 27 44 170 158 71 72 160 125 56 155 284 31 77 184 26 185 184 77 69 159 130 154 44 31 15487 41 171 91 126 92 108 197 145 87 8 189 64 92 93197 197 199 16 16 6 181 113 150 27 57 146 54 41 4461 48 48 22 181 121 124 164 138 94 124 61 191 151 1029 14 36 15 179 7 87 179 131 20 31 51 198 128 108198 3 164 32 27 41 42 179 147 169 168 97 122 156 183------- test 8 ----20924 519 510 589 901 627 827 814 520 725 674 709 777 512 540 731 695 801 984 51712143 197 55 68 193 181 88 163 109 98 159 36 197 139 45 176 34 128 93 083 25 61 46 5 46 66 5 44 47 100 93 180 176 51 198 50 21 69 119126 54 27 100 145 29 123 2 82 95 148 109 69 106 99 105 142 89 36 2713 144 70 120 170 129 195 15 86 29 24 134 37 147 161 168 123 0 71 114181 94 165 119 198 30 173 25 93 130 126 62 85 34 0 170 131 49 171 1124 108 110 154 55 123 78 74 23 181 54 73 91 173 42 152 83 104 6 132114 67 169 73 145 152 122 80 162 39 95 139 167 167 16 80 75 36 126 106121 108 168 194 52 88 111 187 118 39 53 103 139 108 30 76 57 136 198 4345 107 113 3 0 121 162 169 73 45 86 12 70 122 40 149 184 100 135 6077 154 97 176 186 164 3 147 65 29 119 8 41 166 3 69 188 90 97 35106 16 167 192 107 170 30 164 92 175 107 60 118 172 57 141 152 55 15 14198 83 112 82 94 38 176 54 179 3 104 48 113 121 12 106 50 7 26 25------- test 9 ----25325 197 200 241 175 134 182 166 146 96 51 178 71 191 37 2 196 76 160 134 383 203 120 447 14315119 150 191 103 8 185 79 85 16 87 2 107 50 163 179 88 14 132 65 156 138 171 28 249 2901 129 116 25 38 12 182 43 165 120 12 24 165 171 128 117 162 93 101 36 104 157 95 49 45108 167 12 61 28 15 36 146 136 152 33 130 60 36 133 170 182 101 22 46 289 31 177 16 4035 76 67 75 35 128 115 73 155 24 179 193 6 43 101 7 162 13 25 144 114 73 5 167 108115 164 0 148 79 169 125 169 158 47 66 61 87 94 179 148 190 126 69 21 250 4 53 94 16084 176 8 48 139 26 53 23 187 30 118 13 176 86 145 80 170 19 4 66 171 104 159 134 37161 37 196 23 39 81 71 197 23 191 154 74 163 139 72 114 60 57 73 21 117 184 45 92 178178 112 160 182 179 84 176 126 112 132 159 189 35 153 187 108 18 191 143 41 150 194 76 27 16661 118 68 89 60 1 146 178 178 112 1 183 75 139 180 187 12 42 181 50 17 9 11 123 64110 177 48 127 134 24 125 85 116 46 46 141 18 79 81 124 105 9 125 149 53 95 84 197 136149 3 83 146 66 24 187 170 144 180 17 81 102 98 160 91 15 20 109 193 92 43 116 51 106142 155 177 199 105 155 133 85 148 173 16 166 119 78 149 173 74 14 42 65 125 6 154 193 159191 108 55 103 25 91 52 151 145 100 175 34 58 159 37 125 119 166 160 87 163 106 151 36 7571 77 134 49 45 57 191 22 76 193 181 30 199 60 51 180 144 65 136 187 170 108 152 157 7651 88 172 129 20 157 163 156 56 128 24 135 137 26 41 141 90 79 16 180 2 123 127 162 64------- test 10 ----25826 953 853 512 620 769 722 833 719 754 730 521 908 622 877 737 534 882 560 812 684 787 984 983 78315167 78 129 9 41 56 71 132 29 45 61 152 13 76 172 152 27 21 0 38 24 93 25 155 1884 69 79 59 179 166 107 28 79 63 11 101 95 73 172 70 141 97 72 170 74 132 48 195 13688 97 174 121 28 28 157 29 56 148 1 46 160 188 114 179 49 55 22 20 79 98 144 153 10098 23 58 152 58 197 72 199 1 171 18 57 61 64 78 100 61 192 135 92 80 168 129 144 192178 80 119 78 95 14 15 102 26 135 127 145 130 95 117 193 95 98 19 163 135 81 74 182 85121 35 187 43 113 58 56 152 56 183 162 76 90 43 138 38 142 107 156 197 105 81 95 29 9182 124 77 118 106 55 143 6 18 194 92 145 159 61 132 59 12 80 144 179 39 42 122 51 10214 107 32 188 114 67 127 165 15 100 102 183 5 34 125 28 69 180 69 71 2 114 131 107 4564 107 118 27 151 160 74 129 77 35 188 35 105 160 148 189 122 177 144 139 33 145 5 59 74162 74 58 98 48 123 149 6 35 148 93 2 103 144 189 28 108 91 26 49 150 64 81 166 11987 144 20 64 49 93 51 132 105 185 91 115 74 169 46 154 55 17 159 42 188 163 189 73 16136 7 65 4 4 162 132 166 89 82 10 13 182 92 118 157 123 106 168 127 158 169 84 21 159112 73 38 102 93 185 119 195 97 10 14 156 146 54 190 26 111 44 109 18 83 91 78 193 164175 7 54 63 78 84 60 156 20 84 140 183 130 142 14 41 17 97 14 60 155 27 184 9 156103 173 20 51 174 96 90 35 196 77 122 23 137 43 195 41 70 89 4 26 64 186 170 51 13Keep up the good work!Thanks for your submission!

I have been using usaco for several days. I want to change my image to a new one!

Today, I have a headhunter who finds millions of jobs with an annual salary and is rejected by me. I am not very familiar with that industry. Why is it really honest? I know where my strengths are.

R & D! R & D! R & D!

 

Usaco-2.1-holstein-pass

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.