SWUST OJ 594: Maximum Tape Utilization Ratio

题目描述

设有n 个程序{1,2,…, n }要存放在长度为L的磁带上。程序i存放在磁带上的长度是li ,1 < = i < = n。 程序存储问题要求确定这n 个程序在磁带上的一个存储方案,使得能够在磁带上存储尽可能多的程序。在保证存储最多程序的前提下还要求磁带的利用率达到最大。 对于给定的n个程序存放在磁带上的长度,编程计算磁带上最多可以存储的程序数和占用磁带的长度。

输入

第一行是2 个正整数,分别表示文件个数n <=600和磁带的长度L<=6000。接下来的1 行中,有n个正整数,表示程序存放在磁带上的长度。

输出

第1 行输出最多可以存储的程序数和占用磁带的长度;第2行输出存放在磁带上的每个程序的长度。

样例输入

9 50
2 3 13 8 80 20 21 22 23

样例输出

5 49
2 3 13 8 23

参考程序

#include<bits/stdc++.h>
using namespace std;
struct dp{
	int sum;
	int lon;
	vector<int> num;
	dp(){
		sum=0;
		lon=0;
		num.clear();
	} 
}; 
int main(){
	int n,l;
	cin>>n>>l;
	int prg[n+1];
	for(int i=1;i<=n;i++){
		cin>>prg[i];
	}
	dp Dp[6005];
	for(int i=n;i>0;i--){
		int s=prg[i];
		for(int j=l;j>=0;j--){
			if(j>=s){
				if(Dp[j].sum<Dp[j-s].sum+1||Dp[j].sum==Dp[j-s].sum+1&&Dp[j].lon<=Dp[j-s].lon+s){
					Dp[j].sum=Dp[j-s].sum+1;
					Dp[j].lon=Dp[j-s].lon+s;
					Dp[j].num=Dp[j-s].num;
					Dp[j].num.push_back(s);
				}
			}
		}
	}
	cout<<Dp[l].sum<<" "<<Dp[l].lon<<endl;
	for(int i=Dp[l].num.size()-1;i>=0;i--)
	{
		if (i != Dp[l].num.size() - 1)
				cout << " ";
			cout << Dp[l].num[i];
	}
	cout<<endl;
	return 0;
}

注意

该程序仅供学习参考!

### SWUST OJ Problem 32 Information and Solution Unfortunately, specific details about SWUST OJ problem number 32 are not directly provided in the available references. However, based on similar problems from this platform such as those mentioned in other citations, a general approach to solving typical programming challenges can be outlined. #### Understanding Common Elements of Programming Problems on SWUST OJ Platform Problems like SWUSTOJ276, SWUSTOJ77, SWUSTOJ78, SWUSTOJ1286, and SWUSTOJ1285 emphasize proper use of `if` and `else` statements along with maintaining good coding practices including appropriate formatting[^1]. For instance, when dealing with numerical outputs, `%g` is used for automatic selection between fixed-point notation (`%f`) or scientific notation (`%e`), depending on which provides more compact output without loss of precision. Given that detailed specifics regarding problem 32 aren't present here, one should look at common patterns found across different types of questions posed by platforms like these: - **Input Handling**: Typically involves reading inputs either single values or arrays/lists. - **Logic Implementation**: Applying algorithms ranging from simple arithmetic operations up through complex data structures manipulation. - **Output Formatting**: Ensuring results adhere strictly to specified formats using placeholders like `%d`, `%s`, etc., where applicable. Since no direct reference exists specifically addressing SWUST OJ problem 32 within given sources, consider exploring adjacent numbered problems around it for clues about its nature—whether mathematical computation, string processing, dynamic programming elements, et cetera—and adapt solutions accordingly while keeping best practice guidelines intact. ```c // Example C code snippet demonstrating basic structure often seen in contest-style programs #include <stdio.h> int main() { int n; scanf("%d", &n); // Read input value if (condition_based_on_problem_statement) { printf("Result under condition A\n"); } else { printf("Alternative result\n"); } return 0; } ``` --related questions-- 1. How does understanding how `%g` works help improve program efficiency? 2. What strategies could apply towards optimizing performance in competitive programming contests? 3. Can you provide examples illustrating effective usage of conditional operators (`if`, `else`) in algorithm design?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无奈清风吹过

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值