博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 10306 - e-Coins(二维完全背包)
阅读量:4035 次
发布时间:2019-05-24

本文共 2994 字,大约阅读时间需要 9 分钟。

1、

2、题目大意:

对于每个样例,先给定两个数n,m,分别表示有n种硬币,对于每一种硬币有两个价值,分别记做x,y,题目要求从中选择一些硬币,使得满足m=sqrt(x^2+y^2),其中是选出的硬币的所有x的和,y是所有选出的硬币的y的和,硬币有无数多个,现在要求的是,满足上述要求使用的最少的硬币数

本题可以看成是一个二维的完全背包问题,其中m看做是容量,个数看做是价值,现在转化成当前容量下用的最小的价值

3、AC代码:

#include
#define N 45#define INF 0x7fffffff#include
using namespace std;int w1[N],w2[N];int dp[305][305];int main(){ int t,n,m; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i

4、题目:

Problem G

e-Coins

Input: standard input

Output: standard output

Time Limit: 10 seconds

Memory Limit: 32 MB

At the Department for Bills and Coins, an extension of today's monetary system has newly been proposed, in order to make it fit the new economy better. A number of new so called e-coins will be produced, which, in addition to having a value in the normal sense of today, also have an InfoTechnological value. The goal of this reform is, of course, to make justice to the economy of numerous dotcom companies which, despite the fact that they are low on money surely have a lot of IT inside. All money of the old kind will keep its conventional value and get zero InfoTechnological value.

To successfully make value comparisons in the new system, something called the e-modulus is introduced. This is calculated asSQRT(X*X+Y*Y), where X and Y hold the sums of the conventional and InfoTechnological values respectively. For instance, money with a conventional value of $3 altogether and an InfoTechnological value of $4 will get an e-modulus of $5. Bear in mind that you have to calculate the sums of the conventional and InfoTechnological values separately before you calculate the e-modulus of the money.

To simplify the move to e-currency, you are assigned to write a program that, given the e-modulus that shall be reached and a list of the different types of e-coins that are available, calculates the smallest amount of e-coins that are needed to exactly match the e-modulus. There is no limit on how many e-coins of each type that may be used to match the given e-modulus.

Input

A line with the number of problems n (0<n<=100), followed by n times:

  • A line with the integers m (0<m<=40) and S (0<S<=300), where m indicates the number of different e-coin types that exist in the problem, and S states the value of the e-modulus that shall be matched exactly.
  • m lines, each consisting of one pair of non-negative integers describing the value of an e-coin. The first number in the pair states the conventional value, and the second number holds the InfoTechnological value of the coin.

When more than one number is present on a line, they will be separated by a space. Between each problem, there will be one blank line.

 

Output

The output consists of n lines. Each line contains either a single integer holding the number of coins necessary to reach the specified e-modulus Sor, if S cannot be reached, the string "not possible".

Sample Input:

3 

2 5 
0 2 
2 0

3 20 

0 2 
2 0 
2 1

3 5 

3 0 
0 4 
5 5

Sample Output:

not possible 

10 
2

转载地址:http://bhddi.baihongyu.com/

你可能感兴趣的文章
coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数
查看>>
coursesa课程 Python 3 programming The while Statement
查看>>
course_2_assessment_6
查看>>
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
查看>>
coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
查看>>
在unity中建立最小的shader(Minimal Shader)
查看>>
1.3 Debugging of Shaders (调试着色器)
查看>>
关于phpcms中模块_tag.class.php中的pc_tag()方法的含义
查看>>
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
补充自动屏蔽攻击ip
查看>>
谷歌走了
查看>>
多线程使用随机函数需要注意的一点
查看>>
getpeername,getsockname
查看>>
让我做你的下一行Code
查看>>
浅析:setsockopt()改善程序的健壮性
查看>>
关于对象赋值及返回临时对象过程中的构造与析构
查看>>
VS 2005 CRT函数的安全性增强版本
查看>>
SQL 多表联合查询
查看>>
Visual Studio 2010:C++0x新特性
查看>>