1. 程式人生 > >poj Space Elevator 2392 (多重揹包)

poj Space Elevator 2392 (多重揹包)

Space Elevator
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10212 Accepted: 4855

Description

The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h_i (1 <= h_i <= 100) and is available in quantity c_i (1 <= c_i <= 10). Due to possible damage caused by cosmic rays, no part of a block of type i can exceed a maximum altitude a_i (1 <= a_i <= 40000).

Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.

Input

* Line 1: A single integer, K

* Lines 2..K+1: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+1 describes block type i.

Output

* Line 1: A single integer H, the maximum height of a tower that can be built

Sample Input

3
7 40 3
5 23 8
2 52 6

Sample Output

48
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define INF 0x3f3f3f3f 
#define ll long long
#define N 40010
using namespace std;
struct zz
{
	int h;
	int num;
	int mh;
}q[410];
int dp[N];
int cmp(zz a,zz b)
{
	return a.mh<b.mh;
}
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
			scanf("%d%d%d",&q[i].h,&q[i].mh,&q[i].num);
		sort(q,q+n,cmp);
		memset(dp,0,sizeof(dp));
		for(i=0;i<n;i++)
		{
			for(k=1;k<=q[i].num;k++)
			{
				for(j=q[i].mh;j>=q[i].h;j--)
				{
					dp[j]=max(dp[j],dp[j-q[i].h]+q[i].h);
				}
			}
		}
		int ans=0;
		for(i=0;i<=q[n-1].mh;i++)
			ans=max(ans,dp[i]);
		printf("%d\n",ans);
	}
	return 0;
}

相關推薦

poj Space Elevator 2392 多重揹包

Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10212 Accepted: 4855 Description The cows are going to spac

Space Elevator多重揹包

Problem Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of bloc

poj刷題debug日記:poj1276多重揹包

Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39032

HDU 2191 - 悼念512汶川大地震遇難同胞——珍惜現在,感恩生活 多重揹包

題目 急!災區的食物依然短缺! 為了挽救災區同胞的生命,心繫災區同胞的CK準備自己採購一些糧食支援災區,現在假設CK一共有資金n元,而市場有m種大米,每種大米都是袋裝產品,其價格不等,並且只能整袋購買。 請問:CK能用有限的資金最多能採購多少公斤糧食呢? Input 輸入資料首先

悼念512汶川大地震遇難同胞——珍惜現在,感恩生活多重揹包

Description 急!災區的食物依然短缺! 為了挽救災區同胞的生命,心繫災區同胞的你準備自己採購一些糧食支援災區,現在假設你一共有資金n元,而市場有m種大米,每種大米都是袋裝產品,其價格不等,並且只能整袋購買。 請問:你用有限的資金最多能採購多少公斤糧食呢? 後記: 人生是一個充滿了變

SDOJ1037 慶功會多重揹包

傳送門 【題目分析】 然而蒟蒻並不會單調佇列優化。。。。同時也很懶不想寫二進位制拆分。。。。。所以直接上了三重迴圈暴力。。。 【程式碼~】 #include<bits/stdc++.h> using namespace std; const int MAXN=1e4+10

Transport Ship多重揹包

#include<iostream> #include<cstdio> #include<algorithm> #include<string.h> using namespace std; int v[20],

POJ 3624 Charm Bracelet01 揹包

題目傳送門 Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best

2844 Coins多重揹包

題目連結 題意:     有n種硬幣,給出每種硬幣的幣值A[i]和數量C[i],求1到m中能組成幾個值 思路:     多重揹包問題,就是完全揹包但是限制了每種的數量; #include <iostream> #include <cstrin

悼念512汶川大地震遇難同胞——珍惜現在,感恩生活 多重揹包

題目 急!災區的食物依然短缺! 為了挽救災區同胞的生命,心繫災區同胞的CK準備自己採購一些糧食支援災區,現在假設CK一共有資金n元,而市場有m種大米,每種大米都是袋裝產品,其價格不等,並且只能整袋購買。 請問:CK能用有限的資金最多能採購多少公斤糧食呢

hdu2079 選課時間(題目已修改,注意讀題)多重揹包

本題剛開始一看求方案數,當場懵逼,現在求的揹包都是最大容量,這題還能叫揹包麼?(我也不造) 一看小資料,二進位制也不用優化(其實是不會這半揹包型別)。然後判斷其揹包是否裝滿,裝滿就要分開初始化。這題

Coins多重揹包

Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hibix opened purse and found there were some coins.

POJ 2392 Space Elevator 多重揹包 + 思路題

題目連結:http://poj.org/problem?id=2392 Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7783 Accepted: 3690

poj 2392Space Elevator貪心+多重揹包

Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13340 Accepted: 6323 Description The cows ar

POJ 2392 Space Elevator帶限制條件的多重揹包

大意:一群牛用石塊堆天梯,不同的石塊有不同的高度和最高的堆疊高度,求最終的高度。 分析:覺得是多重揹包,但是有了高度的限制。看了別人寫的程式碼半天才緩過來。啊,這樣處理。DP路漫漫。。 #inclu

poj 2392 Space Elevator 排序貪心+多重揹包 仍然很水 ★★

Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9955 Accepted: 4731 Description The cows are going to s

POJ 2392 Space Elevator多重揹包,排序

POJ 2392 Space Elevator 題目傳送門 題意: 你需要建一個高塔,材料總共有K種,每種材料有三個屬性:高度,數量,限度。限度是指該種材料只能在低於該限度的高度下被使用。問你最高能夠把這個高塔建到多高。 解題過程: 這題

poj 2392 Space Elevator(多重揹包

題意: k種石頭(不用在意具體是什麼東西),每種石頭的高度為h,這種石頭不能處於超過a的高度,數量為c,問最多能用這些石頭疊出多大的高度 解題思路: 這是一道稍微有點改動的多重揹包題目,被改為每種石頭都有一個容量限制。 多重揹包的問題我們可以進行轉換,對於c*h>=

Cash Machine POJ 1276多重揹包——二進位制優化

題意:給你一個最大金額m,現在有n種類型的紙票,這些紙票的個數各不相同,問能夠用這些紙票再不超過m的前提下湊成最大的金額是多少? 題解:寫了01揹包直接暴力,結果T了,時間複雜度太高了,要跑外迴圈

POJ 1014 Dividing 多重揹包問題+遞迴【模板】

Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of