蛙人(ple)

來源:互聯網
上載者:User

標籤:

蛙人(ple)題目描述

蛙人使用特殊裝置潛水。裝置中有一個氣瓶,分兩格:一格裝氧氣,另一格裝氮氣。留在水中有時間的限制,在深水中需要大量的氧氣與氮氣。為完成任務,蛙人必須安排好氣瓶。每個氣瓶可以用它的重量和含有氣體的體積來描述。蛙人要完成任務,就需要特定數量的氧氣與氮氣。要完成任務,他所需帶的氣瓶的總重量最少是多少呢?例如:蛙人有下述五個氣瓶。每個氣瓶表述為:氧氣的體積,氮氣的體積(以“升”為單位)和氣瓶的重量(以“公錢(10g)”為單位):
3 36 120
10 25 129
5 50 250
1 45 130
4 20 119
如果蛙人需要5升氧氣和60升氮氣,那麼他必須帶兩個氣瓶總重為249(例如說第一個與第二個或第四個與第五個)。
你的任務是:編一條程式,從文字檔PLE.IN讀入蛙人對氧氣與氮氣的需求,可得氣瓶的數量以及它們的描述,計算蛙人完成任務最少需要帶多重的氣瓶;把結果寫入文字檔PLE.OUT中。
備忘:給出的資料總能找到完成任務的方法

輸入

第一行是兩個整數 t,a 用一個空格隔開,1<=t<=21 且 1<=a<=79。他們表示完成任務需要的氧氣與氮氣的體積。
第二行有一個整數,1<=n<=1000,表示可用的氣瓶數量。接下來n行是對氣瓶的描述;第(i+2)行包含三個整數ti, ai, wi用一個空格隔開,(1<=ti<=21, 1<=ai<=79, 1<=wi<=800)。它們表示:第i瓶中氧氣與氮氣的體積,以及這個氣瓶的重量。

輸出

輸出只有一行。這個整數是完成任務最少需要攜帶氣瓶的總重量。

範例輸入
5 6053 36 12010 25 1295 50 2501 45 1304 20 119
範例輸出
249
分析:dp[i][j]表示氧氣需求量為i,氮氣需求量為j時最小載重量,轉移時注意dp[i][j]<=dp[k][t](i<=k&&j<=t時);
代碼:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <climits>#include <cstring>#include <string>#include <set>#include <map>#include <queue>#include <stack>#include <vector>#include <list>#include <ext/rope>#define rep(i,m,n) for(i=m;i<=n;i++)#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)#define vi vector<int>#define pii pair<int,int>#define mod 1000000007#define inf 0x3f3f3f3f#define pb push_back#define mp make_pair#define fi first#define se second#define ll long long#define pi acos(-1.0)const int maxn=1e3+10;const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespace std;using namespace __gnu_cxx;ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}int n,m,dp[100][100];int main(){    int i,j,k,t;    memset(dp,inf,sizeof(dp));    dp[0][0]=0;    scanf("%d%d",&n,&m);    scanf("%d",&t);    while(t--)    {        int a[3];        rep(i,0,2)scanf("%d",&a[i]);        for(i=21;i>=a[0];i--)            for(j=79;j>=a[1];j--){            if(i>=a[0]&&j>=a[1])dp[i][j]=min(dp[i][j],dp[i-a[0]][j-a[1]]+a[2]);        }        for(i=21;i>=0;i--)        {            int now=inf;            for(j=79;j>=0;j--)                dp[i][j]=min(min(dp[i][j],now),dp[i+1][j]),now=min(now,dp[i][j]);        }    }    printf("%d\n",dp[n][m]);    //system ("pause");    return 0;}

 

 

蛙人(ple)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.