POJ 1010 STAMPS

STAMPS
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13528 Accepted: 3749

Description

Have you done any Philately lately? 

You have been hired by the Ruritanian Postal Service (RPS) to design their new postage software. The software allocates stamps to customers based on customer needs and the denominations that are currently in stock. 

Ruritania is filled with people who correspond with stamp collectors. As a service to these people, the RPS asks that all stamp allocations have the maximum number of different types of stamps in it. In fact, the RPS has been known to issue several stamps of the same denomination in order to please customers (these count as different types, even though they are the same denomination). The maximum number of different types of stamps issued at any time is twenty-five. 

To save money, the RPS would like to issue as few duplicate stamps as possible (given the constraint that they want to issue as many different types). Further, the RPS won't sell more than four stamps at a time. 

Input

The input for your program will be pairs of positive integer sequences, consisting of two lines, alternating until end-of-file. The first sequence are the available values of stamps, while the second sequence is a series of customer requests. For example: 

1 2 3 0 ; three different stamp types 
7 4 0 ; two customers 
1 1 0 ; a new set of stamps (two of the same type) 
6 2 3 0 ; three customers 

Note: the comments in this example are *not* part of the data file; data files contain only integers.

Output

For each customer, you should print the "best" combination that is exactly equal to the customer's needs, with a maximum of four stamps. If no such combination exists, print "none". 
The "best" combination is defined as the maximum number of different stamp types. In case of a tie, the combination with the fewest total stamps is best. If still tied, the set with the highest single-value stamp is best. If there is still a tie, print "tie". 

For the sample input file, the output should be: 

7 (3): 1 1 2 3 
4 (2): 1 3 
6 ---- none 
2 (2): 1 1 
3 (2): tie 

That is, you should print the customer request, the number of types sold and the actual stamps. In case of no legal allocation, the line should look like it does in the example, with four hyphens after a space. In the case of a tie, still print the number of types but do not print the allocation (again, as in the example).Don't print extra blank at the end of each line. 

Sample Input

1 2 3 0	; three different stamp types
7 4 0		; two customers
1 1 0		; a new set of stamps (two of the same type)
6 2 3 0	; three customers

Sample Output

7 (3): 1 1 2 3 
4 (2): 1 3 
6 ---- none
2 (2): 1 1
3 (2): tie

=================================================================================================
这个题目就是DFS搜索了...减枝条件是超用户需求,数量超4
还有网上提到对于n(n>4)张邮票有相同值,可以去掉超过4的那些邮票.
自己写的代码烂的不行..有时间再重新刷.

#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;


int need = 0;//客户需求
int sum = 0;//已经达到的
vector<int> table;//使用了哪些
int ntype = 0;//使用的种类
int nstamp = 0;//使用的数量
int number = 0;//使用的数量

int max_types = -1000;//使用最多的种类
int min_stamp = 1000;//使用最少的邮票
int max_value = -100;//包含最大的邮票
vector<int> best_collection;
int count = 0; //相同方案数量

void search(vector<int> &types,int dep=0)
{
	//加起来超过需要或者使用的种类超过4
	if(sum > need || ntype > 4 || nstamp > 4) return;


	if(sum == need)//满足需求
	{
		int mmax = -100;
		for(unsigned int i=0;i<table.size();++i)
		{
			if(table[i] != 0)
			{
				mmax = max(mmax,types[i]);
			}
		}

		if((ntype > max_types) || (ntype == max_types && nstamp < min_stamp) || (ntype == max_types && nstamp == min_stamp && mmax > max_value))
		{
			best_collection = table;
			max_types = ntype;
			max_value = mmax;
			min_stamp = nstamp;
			count  = 1;
		}
		else if(nstamp == min_stamp && mmax == max_value && ntype == max_types)
		{
			count += 1;
		}
	}

	if(sum < need && dep < (int)types.size())
	{
		int v = types[dep];//当前票值
		//1.不用当前票
		search(types,dep+1);
		//2.用当前票
		if(ntype + 1 > 4) return;
		int old_sum = sum;
		int old_stamp = nstamp;
		ntype += 1;
		for(unsigned i=1;;++i)
		{
			//用i张
			int sv = i*v + old_sum;//值
			if(sv > need) break;
			nstamp = old_stamp + i;//用的数量
			table[dep] = i;//用i张
			sum = sv;
			search(types,dep+1);
		}
		ntype -= 1;
		sum = old_sum;
		nstamp = old_stamp;
		table[dep] = 0;
	}
}

void solve(vector<int> &types,vector<int> &customers)
{
	for(unsigned int i=0;i<customers.size();++i)
	{
		table = vector<int>();
		table.resize(30);

		max_value = -1000;
		max_types = -1000;
		min_stamp = 1000;

		ntype = 0;
		nstamp = 0;
		number = 0;
		sum = 0;

		count = 0;
		need = customers[i];
		search(types);
		if(count == 0)
		{
			printf("%d ---- none\n",need);
		}
		if(count == 1)
		{
			printf("%d (%d):",need,max_types);
			for(unsigned int i=0;i<best_collection.size();++i)
			{
				int n = best_collection[i];
				for(int j=0;j<n;++j)
				{
					printf(" %d",types[i]);
				}
			}
			printf("\n");

		}
		if(count > 1)
		{
			printf("%d (%d): tie\n",need,max_types);
		}
	}
}

void next_line()
{
	while(getchar()!='\n');
}
int main()
{
	freopen("1010.data","r",stdin);
	while(true)
	{
		vector<int> types;
		int n;
		while(cin>>n)
		{
			if(n == 0) break;
			types.push_back(n);
		}
		if(!cin) break;
		next_line();
		vector<int> customers;
		while(cin>>n)
		{
			if(n == 0) break;
			customers.push_back(n);
		}
		next_line();
		solve(types,customers);
	}

	return 0;
}

  

转载于:https://www.cnblogs.com/lssnail/archive/2012/12/16/2820973.html

本项目是一个基于SSM(Spring+SpringMVC+MyBatis)后端框架与Vue.js前端框架开发的疫情居家办公系统。该系统旨在为居家办公的员工提供一个高效、便捷的工作环境,同时帮助企业更好地管理远程工作流程。项目包含了完整的数据库设计、前后端代码实现以及详细的文档说明,非常适合计算机相关专业的毕设学生和需要进行项目实战练习的Java学习者。 系统的核心功能包括用户管理、任务分配、进度跟踪、文件共享和在线沟通等。用户管理模块允许管理员创建和管理用户账户,分配不同的权限。任务分配模块使项目经理能够轻松地分配任务给团队成员,并设置截止日期。进度跟踪模块允许员工实时更新他们的工作状态,确保项目按计划进行。文件共享模块提供了一个安全的平台,让团队成员可以共享和协作处理文档。在线沟通模块则支持即时消息和视频会议,以增强团队之间的沟通效率。 技术栈方面,后端采用了Spring框架来管理业务逻辑,SpringMVC用于构建Web应用程序,MyBatis作为ORM框架简化数据库操作。前端则使用Vue.js来实现动态用户界面,搭配Vue Router进行页面导航,以及Vuex进行状态管理。数据库选用MySQL,确保数据的安全性和可靠性。 该项目不仅提供了一个完整的技术实现示例,还为开发者留下了扩展和改进的空间,可以根据实际需求添加新功能或优化现有功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值