UVA - 10306 e-Coins
来源:互联网 发布:linux c程序编译 编辑:程序博客网 时间:2024/06/04 12:19
题目:
有n种物品,每种物品有x, y两个价值,并且可以有无限多个。
给定s,使得(x1+x2+....)^2 + (y1+y2+....)^2 = s ^ 2。并且物品个数最少。
啊,一顿完全背包之后……再扫一顿……就可以了
#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;int dp[1010][1010];int x[50],y[50];int main(){int T,n,s,i,j,ans,k,inf;cin>>T;while(T--){cin>>n>>s;for(i=0;i<n;i++)cin>>x[i]>>y[i];memset(dp,127,sizeof(dp));inf=*dp[0];dp[0][0]=0;for(i=0;i<=s;i++)for(j=0;j<=s;j++)for(k=0;k<n;k++)if(i>=x[k]&&j>=y[k])dp[i][j]=min(dp[i][j],dp[i-x[k]][j-y[k]]+1);ans=inf;for(i=0;i<=s;i++)for(j=0;j<=s;j++)if(i*i+j*j==s*s)ans=min(ans,dp[i][j]);if(ans==inf)cout<<"not possible"<<endl;elsecout<<ans<<endl;}return 0;}
SubmitStatus
Description
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 ofIT 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 byn times:
- A line with the integers m (0<m<=40) andS (0<S<=300), where m indicates the number of different e-coin types that exist in the problem, andS 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-modulusS or, 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
(Joint Effort Contest, Problem Source: Swedish National Programming Contest, arranged by department of Computer Science at Lund Institute of Technology.)
Source
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 5. Dynamic Programming
Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Problem Solving Paradigms :: Dynamic Programming ::Coin Change (CC)
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Problem Solving Paradigms :: Dynamic Programming ::Coin Change (CC)
- uva 10306 e-Coins
- UVA 10306 e-Coins
- uva 10306 e-Coins
- UVa 10306 - e-Coins
- UVA - 10306 e-Coins
- UVa:10306 e-Coins
- UVA 10306 e-Coins
- uva 10306 - e-Coins
- UVa 10306 - e-Coins
- UVA - 10306 e-Coins
- UVA - 10306 e-Coins
- UVA - 10306 e-Coins
- UVA 10306 - e-Coins
- uva 10306 - e-Coins
- UVA 10306--e-Coins+dp
- UVA 10306 - e-Coins(完全背包)
- uva 10306 - e-Coins(完全背包)
- uva 10306 e-Coins(二维完全背包)
- xamarn.android binding parse sdk for a week to work
- solaris10的系统常用检查命令
- timus 2031. Overturned Numbers
- Java对存储过程的调用方法
- 学习JMF框架遇到的问题及总结
- UVA - 10306 e-Coins
- solaris查看内存、CPU、硬盘总数和使用情况情况
- urllib 传参
- android笔记16-Notification
- c++之指针作为函数参数传递的问题
- Beginning Auto Layout Tutorial in iOS 7: Part 1
- Android的计量单位px,in,mm,pt,dp,dip,sp
- android笔记17- 各种menu
- maven核心,pom.xml详解