zoukankan      html  css  js  c++  java
  • NYIST 749 蚂蚁的难题(八)

    蚂蚁的难题(八)
    时间限制:2000 ms | 内存限制:65535 KB
    难度:5


    描述
    蚂蚁是一个古玩爱好者,他收藏了很多瓶瓶罐罐。

    有一天,他要将他的宝贝们一字排开, 摆放到一个长度为L的展台上。

    已知他有n件宝贝, 每件宝贝的宽为w,由于这些瓶瓶罐罐的形状特殊,所以在摆放时需要至少X的宽度来摆放他们,(仅摆放时需要X的宽度, 摆放后宽度仍为w)现在已知了每件宝贝的宽度wi,和摆放它们所需的宽度Xi。请你帮蚂蚁计算一下,在这个展台上,他最多能摆多宽的宝贝。

    输入
    有多组测试数据。
    对于每一组测试数据:
    第一行: n L 分别代表有n件宝贝,展台长度为L;(n<1000, L<10000)
    接下来有n行, 每行有两个整数 wi xi 分别代表第i件宝贝的宽度和摆放时需要的宽度。(0<wi <= xi < 10000).
    输出
    输出蚂蚁能够摆出的最大的宽度。
    样例输入
    3 10
    2 3
    3 4
    4 7
    样例输出
    9
    提示
    蚂蚁的难题大结局,祝大家水题开心,天天AC!
    来源
    蚂蚁系列
    上传者

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 const int maxn = 10001;
    18 struct node{
    19     int w,x;
    20     bool operator<(const node &u) const{
    21         return x-w > u.x - u.w;
    22     }
    23 };
    24 node p[maxn];
    25 int n,L,dp[maxn];
    26 int main() {
    27     while(~scanf("%d %d",&n,&L)){
    28         for(int i = 1; i <= n; ++i)
    29             scanf("%d %d",&p[i].w,&p[i].x);
    30         sort(p+1,p+n+1);
    31         memset(dp,0,sizeof(dp));
    32         int ans = 0;
    33         for(int i = 1; i <= n; ++i){
    34             for(int j = L; j >= p[i].w; --j){
    35                if(j-p[i].w <= L - p[i].x) dp[j] = max(dp[j],dp[j-p[i].w]+p[i].w);
    36                ans = max(ans,dp[j]);
    37             }
    38         }
    39         printf("%d
    ",ans);
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    如何实现Android欢迎页
    创建webapi的简单步骤
    IOS里Request的斗争(上)
    预告:关于接下来的部分,都是番外。
    利用Selenium制作python数据抓取,以及对Selenium资源介绍
    利用openpyxl来读取Excel数据
    在pycharm下快速添加插件
    C# 分布式缓存服务器方案
    2014中国省市数据库
    FormsAuthentication 登录兼容 IE11 保存cookie
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4047119.html
Copyright © 2011-2022 走看看