zoukankan      html  css  js  c++  java
  • 洛谷:P1048 采药

    #include<iostream>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int max(int a,int b){return a>b?a:b;}
    int map[1003][1003],T,n,input[103][2];
    //图表
    int f(int xx,int yy){
        if(xx<=0 || yy<0)return 0;//如果在此范围内为0
        else{
            if(map[yy][xx]!=0)return map[yy][xx]; 
            int temp=xx-input[yy][0];//目前背包是否可容下当前物品
            if(temp>=0){//可以的话
                temp=f(xx-input[yy][0],yy-1)+input[yy][1];
                //计算装这个的话最大是多少
            }else{temp=0;}
            int temp1=max(f(xx,yy-1),temp);
            return map[yy][xx]=temp1;
            //对比装不装的结果
        }
    }
    int main(){
        int i;
        cin>>T>>n;
        for(i=0;i<n;i++)cin>>input[i][0]>>input[i][1];
    
        cout<<f(T,n-1);
        if(0){//输出建立的表格
            cout<<"	";
            for(i=0;i<T;i++)cout<<i+1<<"	";
            cout<<endl;
            for(i=0;i<n;i++){
                cout<<input[i][0]<<"	";
                for(int xx=1;xx<=T;xx++){
                    cout<<map[i][xx]<<"	";
                }
                cout<<endl;
            }
        }
        return 0;
    
    }

    https://www.luogu.com.cn/problem/P1048

  • 相关阅读:
    02-模板字符串
    01-学习vue前的准备工作
    21-z-index
    20-定位
    19-background
    18-超链接导航栏案例
    17-文本属性和字体属性
    16-margin的用法
    jBPM
    Table of Contents
  • 原文地址:https://www.cnblogs.com/forwhat00/p/13235953.html
Copyright © 2011-2022 走看看