usaco-2.1-holstein-pass

这种问题以前没有遇见过,折腾了近一天,好歹弄明白了,这个源程序才精妙:

/*
ID: qq104801
LANG: C++
TASK: holstein
*/

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

#define VMAX 25
#define GMAX 15

int 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: holstein
LANG: C++

Compiling...
Compile: OK

Executing...
   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 ----
1
50
1
50
------- test 2 ----
3
100 200 300
3
99 199 299
2 2 2
1000 1000 1000
------- test 3 ----
4
1 1 1 1
4
1 1 0 0
1 0 1 0
0 1 0 1
0 0 0 1
------- test 4 ----
5
10 20 30 40 50
5
10 10 10 10 10
0 10 10 10 10
0 0 10 10 10
0 0 0 10 10
0 0 0 0 10
------- test 5 ----
8
10 10 10 10 10 10 10 10
7
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
100 100 100 100 100 100 0 0
5 5 5 5 5 5 10 0
5 5 5 5 5 5 0 10
------- test 6 ----
5
163 221 146 425 509
10
98 69 68 18 129
132 185 196 64 176
40 70 57 9 115
73 189 145 87 117
45 114 45 0 18
137 137 174 73 178
48 143 33 142 192
33 107 148 2 158
32 42 153 90 41
165 81 156 7 121
------- test 7 ----
15
335 425 380 283 513 140 360 349 505 187 358 309 485 495 190
10
123 137 194 60 137 89 153 122 115 198 47 76 38 62 112
31 105 1 155 93 25 74 15 177 191 146 32 47 115 7
116 72 139 64 112 39 173 33 61 118 119 136 32 132 100
37 143 7 159 27 44 170 158 71 72 160 125 56 155 28
4 31 77 184 26 185 184 77 69 159 130 154 44 31 154
87 41 171 91 126 92 108 197 145 87 8 189 64 92 93
197 197 199 16 16 6 181 113 150 27 57 146 54 41 44
61 48 48 22 181 121 124 164 138 94 124 61 191 151 102
9 14 36 15 179 7 87 179 131 20 31 51 198 128 108
198 3 164 32 27 41 42 179 147 169 168 97 122 156 183
------- test 8 ----
20
924 519 510 589 901 627 827 814 520 725 674 709 777 512 540 731 695 801 984 517
12
143 197 55 68 193 181 88 163 109 98 159 36 197 139 45 176 34 128 93 0
83 25 61 46 5 46 66 5 44 47 100 93 180 176 51 198 50 21 69 119
126 54 27 100 145 29 123 2 82 95 148 109 69 106 99 105 142 89 36 27
13 144 70 120 170 129 195 15 86 29 24 134 37 147 161 168 123 0 71 114
181 94 165 119 198 30 173 25 93 130 126 62 85 34 0 170 131 49 171 11
24 108 110 154 55 123 78 74 23 181 54 73 91 173 42 152 83 104 6 132
114 67 169 73 145 152 122 80 162 39 95 139 167 167 16 80 75 36 126 106
121 108 168 194 52 88 111 187 118 39 53 103 139 108 30 76 57 136 198 43
45 107 113 3 0 121 162 169 73 45 86 12 70 122 40 149 184 100 135 60
77 154 97 176 186 164 3 147 65 29 119 8 41 166 3 69 188 90 97 35
106 16 167 192 107 170 30 164 92 175 107 60 118 172 57 141 152 55 15 14
198 83 112 82 94 38 176 54 179 3 104 48 113 121 12 106 50 7 26 25
------- test 9 ----
25
325 197 200 241 175 134 182 166 146 96 51 178 71 191 37 2 196 76 160 134 383 203 120 447 143
15
119 150 191 103 8 185 79 85 16 87 2 107 50 163 179 88 14 132 65 156 138 171 28 249 290
1 129 116 25 38 12 182 43 165 120 12 24 165 171 128 117 162 93 101 36 104 157 95 49 45
108 167 12 61 28 15 36 146 136 152 33 130 60 36 133 170 182 101 22 46 289 31 177 16 40
35 76 67 75 35 128 115 73 155 24 179 193 6 43 101 7 162 13 25 144 114 73 5 167 108
115 164 0 148 79 169 125 169 158 47 66 61 87 94 179 148 190 126 69 21 250 4 53 94 160
84 176 8 48 139 26 53 23 187 30 118 13 176 86 145 80 170 19 4 66 171 104 159 134 37
161 37 196 23 39 81 71 197 23 191 154 74 163 139 72 114 60 57 73 21 117 184 45 92 178
178 112 160 182 179 84 176 126 112 132 159 189 35 153 187 108 18 191 143 41 150 194 76 27 166
61 118 68 89 60 1 146 178 178 112 1 183 75 139 180 187 12 42 181 50 17 9 11 123 64
110 177 48 127 134 24 125 85 116 46 46 141 18 79 81 124 105 9 125 149 53 95 84 197 136
149 3 83 146 66 24 187 170 144 180 17 81 102 98 160 91 15 20 109 193 92 43 116 51 106
142 155 177 199 105 155 133 85 148 173 16 166 119 78 149 173 74 14 42 65 125 6 154 193 159
191 108 55 103 25 91 52 151 145 100 175 34 58 159 37 125 119 166 160 87 163 106 151 36 75
71 77 134 49 45 57 191 22 76 193 181 30 199 60 51 180 144 65 136 187 170 108 152 157 76
51 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 ----
25
826 953 853 512 620 769 722 833 719 754 730 521 908 622 877 737 534 882 560 812 684 787 984 983 783
15
167 78 129 9 41 56 71 132 29 45 61 152 13 76 172 152 27 21 0 38 24 93 25 155 18
84 69 79 59 179 166 107 28 79 63 11 101 95 73 172 70 141 97 72 170 74 132 48 195 136
88 97 174 121 28 28 157 29 56 148 1 46 160 188 114 179 49 55 22 20 79 98 144 153 100
98 23 58 152 58 197 72 199 1 171 18 57 61 64 78 100 61 192 135 92 80 168 129 144 192
178 80 119 78 95 14 15 102 26 135 127 145 130 95 117 193 95 98 19 163 135 81 74 182 85
121 35 187 43 113 58 56 152 56 183 162 76 90 43 138 38 142 107 156 197 105 81 95 29 9
182 124 77 118 106 55 143 6 18 194 92 145 159 61 132 59 12 80 144 179 39 42 122 51 102
14 107 32 188 114 67 127 165 15 100 102 183 5 34 125 28 69 180 69 71 2 114 131 107 45
64 107 118 27 151 160 74 129 77 35 188 35 105 160 148 189 122 177 144 139 33 145 5 59 74
162 74 58 98 48 123 149 6 35 148 93 2 103 144 189 28 108 91 26 49 150 64 81 166 119
87 144 20 64 49 93 51 132 105 185 91 115 74 169 46 154 55 17 159 42 188 163 189 73 161
36 7 65 4 4 162 132 166 89 82 10 13 182 92 118 157 123 106 168 127 158 169 84 21 159
112 73 38 102 93 185 119 195 97 10 14 156 146 54 190 26 111 44 109 18 83 91 78 193 164
175 7 54 63 78 84 60 156 20 84 140 183 130 142 14 41 17 97 14 60 155 27 184 9 156
103 173 20 51 174 96 90 35 196 77 122 23 137 43 195 41 70 89 4 26 64 186 170 51 13

Keep up the good work!
Thanks for your submission!

刷usaco好几天了,想换换uva的口味!

今天有个猎头找茬了年薪百万的工作,被我拒绝了,那个行业,不大熟悉,咋是实诚人,我明白自己的优势在哪。

研发!研发!研发!

时间: 2024-08-30 00:31:01

usaco-2.1-holstein-pass的相关文章

USACO holstein 超时代码

/* ID:kevin_s1 PROG:holstein LANG:C++ */第八组数据跪了,半天都不出结果 #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #includ

USACO holstein AC code

/* ID:kevin_s1 PROG:holstein LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib&g

USACO 之 Section 2.1 (已解决)

The Castle: /* 搜索 1A*/ 1 /* 2 ID: Jming 3 PROG: castle 4 LANG: C++ 5 */ 6 #include <iostream> 7 #include <fstream> 8 #include <sstream> 9 #include <cstdlib> 10 #include <cstdio> 11 #include <cstddef> 12 #include <ite

USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】

holstein解题报告 ------------------------------------------------------------------------------------------------------------------------------------------------[题目] 你需要给一头奶牛制定最优的喂养计划. 有V种维他命,每天对于每种维他命,牛都有需要达到的指标: 同时你有G种饲料,编号依次为1到G,每种维他命在每种饲料中所蕴含的量都会给你.

USACO 做题小结

还记得之前,发过一篇阶段性总结与未来规划..结果由于最近rp爆发(保研成功+进wf)后者显然靠bin神,前者也是运气.因此,放松了一段时间.然后就开始刷usaco了,原因是不用花时间找解题报告在NOCOW上全部都有,很是方便.所以只需单独开一片随笔把每天做题总结一下. Chapter1-Getting started(入门) 都是超级大水题就略过了. Chapter2-Bigger Challenges(更大的挑战) 2.1 castle  这是一道基本的搜索题目,很基础.前面两个值直接搜的,后

【USACO 2.1】Healthy Holsteins

/* TASK: holstein LANG: C++ URL: http://train.usaco.org/usacoprob2?a=SgkbOSkonr2&S=holstein SOLVE: con[i][j]为食物i含有维生素j的量,ned[i]为需要的维生素i的量 bfs,用二进制保存状态 */ #include<cstdio> #define N 30 int v,g,ned[N],con[N][N]; int now[N]; int l,r,q[40000]; bool

USACO Section 2.1 Healthy Holsteins

/* ID: lucien23 PROG: holstein LANG: C++ */ #include <iostream> #include <fstream> #include <vector> using namespace std; bool compFun(int x, int y) { int temp, i = 0; while (true) { temp = 1 << i; if (temp&x > temp&y) {

Usaco Open09 Gold

Problem 1: Ski Lessons [Brian Jacokes, 2002] Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good skier. Bessie has learned that the ski resort is offering S (0 <= S <= 100) ski classes throughout the day. Les

USACO 2.1

USACO 2.1.1 题解: 这题有点毒,调了一个中午…… 先读入,用一个三维布尔数组储存第(i,j)个点的四个方向是否有墙. 对于第一个问题,直接BFS求连通块,并构造出一个图,第(i,j)个点的数字表示该房间属于第几个连通块. 对于第二个问题,边BFS边统计. 对于第三个问题,直接暴力枚举每面墙,找最大值. 对于第四个问题,同样是暴力枚举,但要考虑优先级问题.从右上角的房间枚举到左下角的房间(j=m downto 1;i=1 to n),每个房间先看东墙再看北墙. 代码: { ID:m15

USACO DEC 2019 参赛总结

USACO DEC 2019 参赛总结(2019-12-13~2019-12-16) 2019-12-19 xiaoh 金组Gold A-Milk Pumping 题意 给定一个n个点,m条边的无向图,每一条边都有一个最大流量f和一个价格c(1<=n,m<=1000,1<=c,f<=1000),找一条从1到n的路径(保证存在),求最大化Min{f}/Σ{c}的路径,将这个值×1e6取下整后输出 题解 首先,很明显,当流量最小值固定时,我们只要求满足条件的最小的Σ{c}即可.所以考虑