百度笔试题

#百度#
全部评论
#include <iostream> #include <vector> using namespace std; int main() {     int T;//number of test     cin >> T;     for(int x = 0; x < T; x++)     {         int n, bot, top;         cin >> n >> bot >> top ;         if (n < 1 || n > 10)         {             cout << "input n error!" << endl;             break;         }         if (top < 0 || top > 10000)         {             cout << "input top error!" << endl;             break;         }         int c[10][101], v[10][101];         int m[10];         for (int s = 0; s < n; s++)         {             cin >> m[s];             for (int t = 0; t < m[s]; t++)             {                 cin >> c[s][t] >> v[s][t];             }         }         int maxs = 0;         int consum;         for (int a = 0; a < n; a++)         {             vector<int> f(top, 0);             consum = 0;             for (int i = 0; i < m[a]; ++i)             {                 for (int j = top - 1; j >= bot; --j)                 {                     if (c[a][i] <=j)                     {                         f[j] = max(f[j], f[j - c[a][i]] + v[a][i]);                                                 }                 }                 if (maxs < f[top - 1])                 {                     maxs = f[top - 1];                     consum += c[a][i];                 }             }         }         cout <<consum<<" "<< maxs << endl;     }     return 0; }
点赞 回复 分享
发布于 2015-04-19 21:33
楼上那个有bug好像,不能通过测试。
点赞 回复 分享
发布于 2015-04-19 22:18

相关推荐

2024-12-05 15:53
中南大学 Java
点赞 评论 收藏
分享
2024-12-09 16:31
已编辑
门头沟学院 前端工程师
Apries:这个阶段来说,很厉害很厉害了,不过写的简历确实不是很行,优势删掉吧,其他的还行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务