zoukankan      html  css  js  c++  java
  • HDU 4341 分组背包

    B - Gold miner
    Time Limit:2000MS     
    Memory Limit:32768KB    

    Description

    Homelesser likes playing Gold miners in class. He has to pay much attention to the teacher to avoid being noticed. So he always lose the game. After losing many times, he wants your help. 

    To make it easy, the gold becomes a point (with the area of 0). You are given each gold's position, the time spent to get this gold, and the value of this gold. Maybe some pieces of gold are co-line, you can only get these pieces in order. You can assume it can turn to any direction immediately. 
    Please help Homelesser get the maximum value.
     

    Input

    There are multiple cases. 
    In each case, the first line contains two integers N (the number of pieces of gold), T (the total time). (0<N≤200, 0≤T≤40000) 
    In each of the next N lines, there four integers x, y (the position of the gold), t (the time to get this gold), v (the value of this gold). (0≤|x|≤200, 0<y≤200,0<t≤200, 0≤v≤200)
     

    Output

    Print the case number and the maximum value for each test case.
     

    Sample Input

    3 10 1 1 1 1 2 2 2 2 1 3 15 9 3 10 1 1 13 1 2 2 2 2 1 3 4 7
     

    Sample Output

    Case 1: 3 Case 2: 7
     
    题意:
       黄金矿工的游戏
       同一直线上的金子,只能先抓近的
    题解:分组背包
    ///1085422276
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <queue>
    #include <typeinfo>
    #include <map>
    typedef long long ll;
    using namespace std;
    #define inf 10000000
    inline ll read()
    {
        ll x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9')
        {
            if(ch=='-')f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9')
        {
            x=x*10+ch-'0';
            ch=getchar();
        }
        return x*f;
    }
    //***************************************************************
    
    struct ss
    {
        int x,y,v,t;
    }p[2050];
    vector<ss >belong[2050];
    bool cmp(ss a,ss b)
    {
        if(a.y*b.x!=a.x*b.y)
            return a.y*b.x<a.x*b.y;
        else return a.y<b.y;
    }
    int dp[40005];
    int main()
    {
    
        int oo=1;
        int n,m;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            memset(dp,0,sizeof(dp));
            for(int i=1;i<=n;i++)belong[i].clear();
            for(int i=1;i<=n;i++)
            {
                scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].t,&p[i].v);
            }
            p[0].x=-1;
            p[0].y=-1;
            sort(p+1,p+n+1,cmp);
            int zu=0;
            for(int i=1;i<=n;i++)
            {
                if(i!=1&&p[i].y*p[i-1].x==p[i].x*p[i-1].y)
                {
                    ss kk;
                    kk.v=belong[zu][belong[zu].size()-1].v+p[i].v;
                    kk.t=belong[zu][belong[zu].size()-1].t+p[i].t;
                    belong[zu].push_back(kk);
                }
                else {
                    ss kk;
                    kk.v=p[i].v;
                    kk.t=p[i].t;
                    belong[++zu].push_back(kk);
                }
    
            }
            //cout<<3213121<<endl;
            for(int i=1;i<=zu;i++)
            {
                for(int j=m;j>=0;j--)
                {
                    for(int k=0;k<belong[i].size();k++)
                    {
                        if(j>=belong[i][k].t)
                        {
                            dp[j]=max(dp[j],dp[j-belong[i][k].t]+belong[i][k].v);
                        }
                    }
                }
            }
            printf("Case %d: %d
    ",oo++,dp[m]);
    
        }
    
        return 0;
    }
    代码狗
     
  • 相关阅读:
    干货:分布式系统详解
    如果有人问你数据库的原理,叫他看这篇文章
    MySQL的B树索引与索引优化
    优化网站性能必备的6种架构方案,你知道吗?
    【干货】手把手教你搭建一套可自动化构建的微服务框架
    你真的理解微服务架构吗
    Android Activity 半透明效果(Translucent)
    Android DatepickerDialog(日期选择器)的使用
    Android搜索自动提示功能 AutocompleteTextView
    Android动态加载ListView中的Item
  • 原文地址:https://www.cnblogs.com/zxhl/p/4746136.html
Copyright © 2011-2022 走看看