zoukankan      html  css  js  c++  java
  • 第三届山东ACM Pick apples

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    using namespace std;
    
    struct node{
        long long S;
        long long P;
        double q;
    }a[3];
    
    bool cmp(node a,node b){
        return a.q>b.q;
    }
    
    int main(){
    
        int T;
        long long V;
        long long sum;
        long long dp[6000];
        long long tmp;
        int i,j;
        int ca=0;
    
    
        scanf("%d",&T);
    
        while(T--){
            scanf("%lld%lld",&a[0].S,&a[0].P);
            a[0].q=(double)(a[0].P)/a[0].S;
            //cout<<a[0].q<<endl;
            scanf("%lld%lld",&a[1].S,&a[1].P);
            a[1].q=(double)(a[1].P)/a[1].S;
            //cout<<a[1].q<<endl;
            scanf("%lld%lld",&a[2].S,&a[2].P);
            a[2].q=(double)(a[2].P)/a[2].S;
            //cout<<a[2].q<<endl;
            scanf("%lld",&V);
    
            sort(a,a+3,cmp);
    
            sum=V%a[0].S;
    
            for(i=1;;++i){
                if(a[0].S*i>=5000){
                    break;
                }
            }
    
            sum=sum+a[0].S*i;
    
            memset(dp,0,sizeof(dp));
    
            for(i=0;i<3;++i){
                for(j=a[i].S;j<=sum;++j){
                    tmp=dp[j-a[i].S]+a[i].P;
                    if(tmp>dp[j]){
                        dp[j]=tmp;
                    }
                }
            }
    
            for(i=sum;;--i){
                if(dp[i]>0){
                    break;
                }
            }
    
            printf("Case %d: %lld
    ",++ca,((V-sum)/a[0].S)*a[0].P+dp[i]);
    
        }
    
        return 0;
    }
    
    
    /**************************************
    	Problem id	: SDUT OJ J 
    	User name	: 666777 
    	Result		: Accepted 
    	Take Memory	: 556K 
    	Take Time	: 0MS 
    	Submit Time	: 2016-04-30 17:44:39  
    **************************************/
    






  • 相关阅读:
    python 学习
    快速排序
    U3D AStar 案例
    U3D AStar 算法原理
    .net core 实时通讯
    .net 算法复杂度
    U3D MVC 背包案例
    U3D 对象池
    Unity网络基础(NetWork)
    U3D Socket实现简易通讯
  • 原文地址:https://www.cnblogs.com/zswbky/p/6717997.html
Copyright © 2011-2022 走看看