典型题,数据多,根据题意组织变量,动态规划,背包,图论。

/*
ID: qq104801
LANG: C++
TASK: shopping
*/#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>using namespace std;#define nmax 1000
#define nmin 6struct special_offer{int n;  //the number of products that are offeredint c[nmin];  //product code c (1 <= c <= 999) int k[nmin];  //k items (1 <= k <= 5) int p;  //the reduced price (1 <= p <= 9999)
}of[nmax];
int offer_num;int b;        //different kinds of products to be purchased
int c[nmin];  //product code
int k[nmin];  //indicates how many items of this product are to be purchased
int p[nmax];  //the regular price per itemint g[nmax];  //product_id->no.
int d[nmin][nmin][nmin][nmin][nmin];  //dp arrayvoid solver()
{for(int u=0;u<=5;u++)for(int v=0;v<=5;v++)for(int w=0;w<=5;w++)for(int x=0;x<=5;x++)for(int y=0;y<=5;y++){d[u][v][w][x][y]=p[0]*u+p[1]*v+p[2]*w+p[3]*x+p[4]*y;int t[5];for(int s=0;s<offer_num;s++){memset(t,0,sizeof(t));for(int r=0;r<of[s].n;r++)if(g[of[s].c[r]]!=-1)t[g[of[s].c[r]]]=of[s].k[r];                        if(u>=t[0]&&v>=t[1]&&w>=t[2]&&x>=t[3]&&y>=t[4])d[u][v][w][x][y]=min(d[u][v][w][x][y],\d[u-t[0]][v-t[1]][w-t[2]][x-t[3]][y-t[4]]+of[s].p);}}cout<<d[k[0]][k[1]][k[2]][k[3]][k[4]]<<endl;
}void test()
{    freopen("shopping.in","r",stdin);freopen("shopping.out","w",stdout);cin>>offer_num;//cout<<offer_num;for(int i=0;i<offer_num;i++){cin>>of[i].n;        for(int j=0;j<of[i].n;j++)cin>>of[i].c[j]>>of[i].k[j];cin>>of[i].p;        }cin>>b;for(int i=0;i<b;i++){cin>>c[i]>>k[i]>>p[i];g[c[i]]=i;}solver();
}int main ()
{        test();        return 0;
}

test data:

USACO Training
Grader Results
9 users online
ARG/1 CHN/2 PHL/1 TWN/1 USA/4

USER: cn tom [qq104801]
TASK: shopping
LANG: C++Compiling...
Compile: OKExecuting...Test 1: TEST OK [0.005 secs, 3468 KB]Test 2: TEST OK [0.005 secs, 3468 KB]Test 3: TEST OK [0.003 secs, 3468 KB]Test 4: TEST OK [0.005 secs, 3468 KB]Test 5: TEST OK [0.008 secs, 3468 KB]Test 6: TEST OK [0.008 secs, 3468 KB]Test 7: TEST OK [0.016 secs, 3468 KB]Test 8: TEST OK [0.022 secs, 3468 KB]Test 9: TEST OK [0.024 secs, 3468 KB]Test 10: TEST OK [0.032 secs, 3468 KB]Test 11: TEST OK [0.054 secs, 3468 KB]Test 12: TEST OK [0.019 secs, 3468 KB]All tests OK.YOUR PROGRAM ('shopping') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----
0
1
3 2 2
------- test 2 ----
2
1 7 3 5
2 7 1 8 2 10
2
7 3 2
8 2 5
------- test 3 ----
0
0
------- test 4 ----
0
5
7 5 111
3 5 222
2 5 333
9 5 444
1 5 555
------- test 5 ----
4
1 641 1 46
1 262 2 200
1 83 3 55
2 24 1 105 2 205
5
641 5 50
262 5 114
83 5 21
24 5 79
105 5 75
------- test 6 ----
4
2 81 1 62 1 149
2 62 1 113 1 147
2 113 1 34 1 77
2 81 1 34 1 75
4
81 1 27
62 2 135
113 3 27
34 4 56
------- test 7 ----
10
1 155 2 150
2 173 1 155 1 177
1 173 2 212
2 112 1 155 1 152
2 112 1 173 1 190
1 112 2 169
2 271 1 155 1 165
2 271 1 173 1 195
2 271 1 112 1 177
1 271 2 181
4
271 3 103
112 3 92
173 3 114
155 3 87
------- test 8 ----
53
1 43 1 10
1 43 2 21
1 43 3 31
1 62 1 32
2 62 1 43 1 43
2 62 1 43 2 57
2 62 1 43 3 64
1 62 2 68
2 62 2 43 1 82
2 62 2 43 2 85
2 62 2 43 3 99
1 62 3 103
2 62 3 43 1 107
2 62 3 43 2 119
2 62 3 43 3 132
1 51 1 22
2 51 1 43 1 33
2 51 1 43 2 44
2 51 1 43 3 52
2 51 1 62 1 55
3 51 1 62 1 43 1 67
3 51 1 62 1 43 2 77
3 51 1 62 1 43 3 84
2 51 1 62 2 94
3 51 1 62 2 43 1 103
3 51 1 62 2 43 2 107
3 51 1 62 2 43 3 126
2 51 1 62 3 124
3 51 1 62 3 43 1 132
3 51 1 62 3 43 2 152
1 51 2 41
2 51 2 43 1 55
2 51 2 43 2 67
2 51 2 43 3 77
2 51 2 62 1 78
3 51 2 62 1 43 1 87
3 51 2 62 1 43 2 94
3 51 2 62 1 43 3 115
2 51 2 62 2 110
3 51 2 62 2 43 1 125
3 51 2 62 2 43 2 138
2 51 2 62 3 152
3 51 2 62 3 43 1 151
1 51 3 62
2 51 3 43 1 72
2 51 3 43 2 84
2 51 3 43 3 92
2 51 3 62 1 102
3 51 3 62 1 43 1 104
3 51 3 62 1 43 2 117
2 51 3 62 2 127
3 51 3 62 2 43 1 142
2 51 3 62 3 158
3
51 3 24
62 3 38
43 3 12
------- test 9 ----
68
2 43 2 64 4 767
2 43 3 64 3 753
2 43 4 64 2 740
3 52 1 43 1 64 4 773
3 52 1 43 2 64 3 823
3 52 1 43 3 64 2 749
3 52 1 43 4 64 1 762
2 52 2 64 4 889
3 52 2 43 1 64 3 820
3 52 2 43 2 64 2 854
3 52 2 43 3 64 1 796
2 52 2 43 4 783
2 52 3 64 3 939
3 52 3 43 1 64 2 916
3 52 3 43 2 64 1 827
2 52 3 43 3 806
2 52 4 64 2 918
3 52 4 43 1 64 1 917
2 52 4 43 2 836
3 21 1 43 1 64 4 758
3 21 1 43 2 64 3 736
3 21 1 43 3 64 2 691
3 21 1 43 4 64 1 647
3 21 1 52 1 64 4 801
4 21 1 52 1 43 1 64 3 805
4 21 1 52 1 43 2 64 2 766
4 21 1 52 1 43 3 64 1 744
3 21 1 52 1 43 4 675
3 21 1 52 2 64 3 840
4 21 1 52 2 43 1 64 2 782
4 21 1 52 2 43 2 64 1 805
3 21 1 52 2 43 3 766
3 21 1 52 3 64 2 860
4 21 1 52 3 43 1 64 1 876
3 21 1 52 3 43 2 781
3 21 1 52 4 64 1 880
3 21 1 52 4 43 1 869
2 21 2 64 4 733
3 21 2 43 1 64 3 719
3 21 2 43 2 64 2 689
3 21 2 43 3 64 1 660
2 21 2 43 4 661
3 21 2 52 1 64 3 745
4 21 2 52 1 43 1 64 2 765
4 21 2 52 1 43 2 64 1 687
3 21 2 52 1 43 3 697
3 21 2 52 2 64 2 801
4 21 2 52 2 43 1 64 1 728
3 21 2 52 2 43 2 732
3 21 2 52 3 64 1 858
3 21 2 52 3 43 1 765
2 21 2 52 4 880
2 21 3 64 3 663
3 21 3 43 1 64 2 680
3 21 3 43 2 64 1 622
2 21 3 43 3 657
3 21 3 52 1 64 2 748
4 21 3 52 1 43 1 64 1 686
3 21 3 52 1 43 2 680
3 21 3 52 2 64 1 737
3 21 3 52 2 43 1 724
2 21 3 52 3 748
2 21 4 64 2 641
3 21 4 43 1 64 1 620
2 21 4 43 2 612
3 21 4 52 1 64 1 693
3 21 4 52 1 43 1 634
2 21 4 52 2 715
4
21 4 107
52 4 183
43 4 126
64 4 150
------- test 10 ----
55
1 55 1 116
1 55 2 237
1 55 3 363
1 64 1 154
2 64 1 55 1 264
2 64 1 55 2 385
1 64 2 315
2 64 2 55 1 408
1 64 3 467
1 23 1 133
2 23 1 55 1 253
2 23 1 55 2 360
2 23 1 64 1 297
3 23 1 64 1 55 1 420
2 23 1 64 2 446
1 23 2 275
2 23 2 55 1 369
2 23 2 64 1 406
1 23 3 404
1 52 1 93
2 52 1 55 1 209
2 52 1 55 2 328
2 52 1 64 1 247
3 52 1 64 1 55 1 374
2 52 1 64 2 386
2 52 1 23 1 232
3 52 1 23 1 55 1 361
3 52 1 23 1 64 1 396
2 52 1 23 2 355
1 52 2 199
2 52 2 55 1 326
2 52 2 64 1 343
2 52 2 23 1 319
1 52 3 295
1 31 1 102
2 31 1 55 1 215
2 31 1 55 2 355
2 31 1 64 1 259
3 31 1 64 1 55 1 377
2 31 1 64 2 425
2 31 1 23 1 230
3 31 1 23 1 55 1 361
3 31 1 23 1 64 1 382
2 31 1 23 2 358
2 31 1 52 1 202
3 31 1 52 1 55 1 310
3 31 1 52 1 64 1 358
3 31 1 52 1 23 1 334
2 31 1 52 2 297
1 31 2 211
2 31 2 55 1 339
2 31 2 64 1 366
2 31 2 23 1 338
2 31 2 52 1 302
1 31 3 320
5
31 5 120
52 5 107
23 5 148
64 5 171
55 5 133
------- test 11 ----
95
1 25 1 183
1 25 2 354
1 25 3 549
1 25 4 748
1 25 5 915
1 94 1 126
2 94 1 25 1 318
2 94 1 25 2 463
2 94 1 25 3 662
1 94 2 276
2 94 2 25 1 429
2 94 2 25 2 602
1 94 3 401
2 94 3 25 1 557
1 94 4 512
1 94 5 625
1 63 1 99
2 63 1 25 1 284
2 63 1 25 2 462
2 63 1 25 3 650
2 63 1 94 1 218
3 63 1 94 1 25 1 424
2 63 1 94 2 343
2 63 1 94 3 490
1 63 2 207
2 63 2 25 1 385
2 63 2 25 2 575
2 63 2 94 1 327
2 63 2 94 2 478
1 63 3 284
2 63 3 25 1 466
2 63 3 94 1 448
1 63 4 405
1 63 5 517
1 72 1 159
2 72 1 25 1 342
2 72 1 25 2 496
2 72 1 25 3 704
2 72 1 94 1 286
3 72 1 94 1 25 1 489
2 72 1 94 2 412
2 72 1 94 3 570
2 72 1 63 1 277
3 72 1 63 1 25 1 420
3 72 1 63 1 94 1 411
2 72 1 63 2 348
2 72 1 63 3 438
1 72 2 315
2 72 2 25 1 518
2 72 2 25 2 660
2 72 2 94 1 450
2 72 2 94 2 618
2 72 2 63 1 432
2 72 2 63 2 537
1 72 3 472
2 72 3 25 1 686
2 72 3 94 1 632
2 72 3 63 1 605
1 72 4 688
1 72 5 805
1 51 1 190
2 51 1 25 1 373
2 51 1 25 2 540
2 51 1 25 3 727
2 51 1 94 1 304
3 51 1 94 1 25 1 477
2 51 1 94 2 446
2 51 1 94 3 547
2 51 1 63 1 278
3 51 1 63 1 25 1 460
3 51 1 63 1 94 1 404
2 51 1 63 2 392
2 51 1 63 3 473
2 51 1 72 1 337
3 51 1 72 1 25 1 551
3 51 1 72 1 94 1 502
3 51 1 72 1 63 1 467
2 51 1 72 2 526
2 51 1 72 3 643
1 51 2 380
2 51 2 25 1 525
2 51 2 25 2 754
2 51 2 94 1 490
2 51 2 94 2 656
2 51 2 63 1 463
2 51 2 63 2 549
2 51 2 72 1 512
2 51 2 72 2 666
1 51 3 570
2 51 3 25 1 700
2 51 3 94 1 663
2 51 3 63 1 652
2 51 3 72 1 728
1 51 4 711
1 51 5 889
5
51 5 202
72 5 185
63 5 110
94 5 147
25 5 199
------- test 12 ----
81
3 73 1 54 1 45 3 1116
3 73 1 54 2 45 2 1116
3 73 1 54 3 45 1 1212
3 73 2 54 1 45 2 1229
3 73 2 54 2 45 1 1314
3 73 3 54 1 45 1 1498
3 82 1 54 1 45 3 996
3 82 1 54 2 45 2 1157
3 82 1 54 3 45 1 1234
3 82 1 73 1 45 3 1082
4 82 1 73 1 54 1 45 2 1261
4 82 1 73 1 54 2 45 1 1237
3 82 1 73 1 54 3 1364
3 82 1 73 2 45 2 1212
4 82 1 73 2 54 1 45 1 1385
3 82 1 73 2 54 2 1520
3 82 1 73 3 45 1 1428
3 82 1 73 3 54 1 1614
3 82 2 54 1 45 2 1107
3 82 2 54 2 45 1 1260
3 82 2 73 1 45 2 1220
4 82 2 73 1 54 1 45 1 1395
3 82 2 73 1 54 2 1405
3 82 2 73 2 45 1 1443
3 82 2 73 2 54 1 1479
3 82 3 54 1 45 1 1272
3 82 3 73 1 45 1 1301
3 82 3 73 1 54 1 1382
3 101 1 54 1 45 3 1046
3 101 1 54 2 45 2 1169
3 101 1 54 3 45 1 1326
3 101 1 73 1 45 3 1236
4 101 1 73 1 54 1 45 2 1285
4 101 1 73 1 54 2 45 1 1387
3 101 1 73 1 54 3 1456
3 101 1 73 2 45 2 1391
4 101 1 73 2 54 1 45 1 1398
3 101 1 73 2 54 2 1529
3 101 1 73 3 45 1 1521
3 101 1 73 3 54 1 1658
3 101 1 82 1 45 3 1121
4 101 1 82 1 54 1 45 2 1291
4 101 1 82 1 54 2 45 1 1397
3 101 1 82 1 54 3 1487
4 101 1 82 1 73 1 45 2 1326
5 101 1 82 1 73 1 54 1 45 1 1429
4 101 1 82 1 73 1 54 2 1447
4 101 1 82 1 73 2 45 1 1522
4 101 1 82 1 73 2 54 1 1537
3 101 1 82 1 73 3 1610
3 101 1 82 2 45 2 1234
4 101 1 82 2 54 1 45 1 1424
3 101 1 82 2 54 2 1498
4 101 1 82 2 73 1 45 1 1359
4 101 1 82 2 73 1 54 1 1507
3 101 1 82 2 73 2 1580
3 101 1 82 3 45 1 1451
3 101 1 82 3 54 1 1475
3 101 1 82 3 73 1 1567
3 101 2 54 1 45 2 1255
3 101 2 54 2 45 1 1431
3 101 2 73 1 45 2 1420
4 101 2 73 1 54 1 45 1 1524
3 101 2 73 1 54 2 1539
3 101 2 73 2 45 1 1479
3 101 2 73 2 54 1 1649
3 101 2 82 1 45 2 1295
4 101 2 82 1 54 1 45 1 1457
3 101 2 82 1 54 2 1525
4 101 2 82 1 73 1 45 1 1533
4 101 2 82 1 73 1 54 1 1690
3 101 2 82 1 73 2 1656
3 101 2 82 2 45 1 1402
3 101 2 82 2 54 1 1482
3 101 2 82 2 73 1 1663
3 101 3 54 1 45 1 1569
3 101 3 73 1 45 1 1576
3 101 3 73 1 54 1 1714
3 101 3 82 1 45 1 1527
3 101 3 82 1 54 1 1555
3 101 3 82 1 73 1 1626
5
101 5 406
82 5 320
73 5 375
54 5 291
45 5 178Keep up the good work!
Thanks for your submission!

转载于:https://www.cnblogs.com/dpblue/p/3972342.html

usaco-3.3-shopping-passed相关推荐

  1. USACO 3.3.2 Shopping Offers解题报告

    写在前面:因为之前没写的C++的USACO Training的解题报告太多--所以就不写了,要是想要代码可以联系我:xiedong_1993@foxmail.com 这题就是传说中的五维背包,其实写起 ...

  2. USACO算法系列十五——shoping

    题目:http://www.nocow.cn/index.php/Translate:USACO/shopping 题目很长,大致意思是买n种商品,然后这几种商品按照不同的组合可以有不同的折扣,要我们 ...

  3. 【USACO题库】 动态规划 汇总(普及-/普及)

    数据结构提高是够用了=-=虽然树状数组没学 但是其他类问题只能打到普及 普及啊啊啊!!! 而且这边省选组都是什么仙人掌啊,什么系什么点对啊...感觉数据结构并没有什么用 (实际上很有用但我不会用就是了 ...

  4. usaco Shaping Regions

    这就是usaco 前面的windows area的变形. /* ID:jinbo wu TASK:rect1 LANG:C++ */ #include<iostream> #include ...

  5. usaco Postal Vans(dp)

    是哈密顿回路,然后...就不知道怎么写了 ,以前写过类似的不过情况没这么多也没这么复 usaco training 6.1.1 Postal Vans 题解 标签: usaco training题解d ...

  6. usaco Beef McNuggets

    这两天贼烦,ccf炸了,还有一个烦心事.哎我都不知道自己能不能坚持下去了.马上期末考了.这段时间还是抓紧时间复习吧同时刷usaco的节奏要跟以前一样了,毕竟课少了. 题解: 只要你知道以下的数论结论, ...

  7. usaco前两章小结

    usaco 暑假老师有推荐做但是那个题目太长了,而且·大部分都是废话做起来特别慢,而且当时自己基本上什么都不懂,太难了所以看了题解做了两题就放弃了. 转眼就上学了,因为想学习acm所以就胡乱找题做但是 ...

  8. usaco ★Fractions to Decimals 分数化小数

    ★Fractions to Decimals 分数化小数 写一个程序,输入一个形如 N/D 的分数(N 是分子,D 是分母),输出它的小数形式. 如果小数有循环节的话,把循环节放在一对圆括号中.例如, ...

  9. usaco ★Bessie Come Home 回家

    ★Bessie Come Home 回家 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃,所以她们开始向谷仓走去. 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有 ...

  10. usaco Sorting a Three-Valued Sequence 三值的排序

    一开始想贪心,但是一想这是搜索章节应该用bfs?(为什么这么想看我上一个usaco的题目),,,,,,,,,,结果我贪心做出来了.然后我百度一下了别人做的好像么没人用bfs我不知道可不可以做出来. 思 ...

最新文章

  1. 郭涛:忽悠 众多人工智能创业公司与AI无关
  2. python3.8.5 应用程序无法启动-macos python3.8.5 打开摄像头问题
  3. Flash学习笔记(01)
  4. 充分发挥bpl包的作用
  5. HSIC简介:一个有意思的判断相关性的思路
  6. OpenCV重新映射Remap的实例(附完整代码)
  7. 想和你一起为 Visual Studio 庆祝20岁生日
  8. 足球预测_预测足球热
  9. 暨南大学计算机复试线2019,暨南大学2019年考研复试分数线
  10. pycharm之no python interpreter configured for project的解决办法
  11. Linux debian ubuntu安装GIMP软件
  12. ORACLE数据库维护
  13. 最好的Linux C/C++ IDE Windows ALL IDE,第一效率,第零浪漫
  14. Substance PBR Guide
  15. 为什么不可以使用哈曼顿距离_声光色影俱佳,美也要与众不同,哈曼卡顿无线水晶4评测...
  16. SELinux permissive模式 设置
  17. MySQL和Navicat for MySQL下载及安装详细教程
  18. 文章原创度检测工具哪个最好用?怎么操作是最好的?
  19. 关于 联想昭阳 E43A 无线开关设置的 正确解决办法
  20. 【已解决】libcef.dll怎么修复?libcef.dll丢失怎么办电脑上总显示

热门文章

  1. 动态主机配置协议DHCP
  2. bzoj 3143: [Hnoi2013]游走(高斯消元)
  3. HDU 6188 2017广西邀请赛:Duizi and Shunzi
  4. 2017 Multi-University Training Contest - Team 4:1004. Dirt Ratio
  5. bzoj 3504: [Cqoi2014]危桥(最大流)
  6. bzoj 2705: [SDOI2012]Longge的问题(欧拉函数)
  7. Java 绘制艺术图案
  8. jQuery Mobile 所有data-*选项,开发全解+完美注释
  9. who whos exist inf
  10. pyqt5_tools下找不到designer.exe新版的designer.exe放在\pyqt5_tools\Qt\bin下