原题:
At the Department for Bills and Coins, an extension of today’s monetary system has newly been pro-
posed, 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 InfoTechno-
logical 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 as SQRT(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 3altogetherandanInfoTechnologicalvalueof3 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 S 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
大意:
每个e-Coin有两个值,一个是conventional value另一个是InfoTechnological value 现在给你一个值,让你用给你的e-Coin组成这个值,计算方方法是你选用的e-Coin的所有con值的平方加上所有info值的平方的和,如果这个和等于题目中给你的值的平方,那就输出你所用e-Coin的最小数量,否则输出not possible

#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<fstream>
#include <limits.h>
using namespace std;
//fstream output,input;int dp[301][301];
int conv[41],info[41];
int main()
{ios::sync_with_stdio(false);int i,j,n,m,s;cin>>n;while(n--){cin>>m>>s;for(int i=0;i<=s;i++)for(int j=0;j<=s;j++)dp[i][j]=999999;for(int i=1;i<=m;i++){cin>>conv[i]>>info[i];dp[conv[i]][info[i]]=1;}for(int k=1;k<=m;k++){for(int i=conv[k];i<=s;i++){for(int j=info[k];j<=s;j++)dp[i][j]=min(dp[i][j],dp[i-conv[k]][j-info[k]]+1);}}int ans=999999;for(int i=0;i<=s;i++){for(int j=0;j<=s;j++){if(i*i+j*j==s*s&&dp[i][j]<ans)ans=dp[i][j];}}if(ans==999999)cout<<"not possible"<<endl;elsecout<<ans<<endl;}
//  input.close();
//  output.close();return 0;
}

解析:
联系完全背包问题,转移方程还不是特别难想到dp[x][y]=min(dp[x][y],dp[x-conv[k]][y-info[k]]+1),x和y分别代表conv值的总和以及info值的总和,dp[x][y]表示满足conv的总和为x,info的总和为y时的所用的最小e-coin的数量,接下来没完。然后继续枚举每个x和y的值,判断x*x+y*y是否等于s*s,并求出最小的dp值即可。

uva 10306 e-Coin相关推荐

  1. UVA 10306 e-Coins(全然背包: 二维限制条件)

    UVA 10306 e-Coins(全然背包: 二维限制条件) http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...

  2. UVA 10306 e-Coins (二维背包)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. uva 10306(完全背包)

    题意:有m种硬币和目标值s,如果能最少拿k个可以让拿出的硬币的x的和和y的和的平方和等于s的平方,输出k. 题解:完全背包问题,f[i][j]代表当硬币的x和y分别为i和j时最少共有多少个硬币组成,然 ...

  4. UVA - 10306 e-Coins

    题目大意:给出m和s, 再给出m种电子硬币,每种硬币有两种金额xi,yi.现在要在m种硬币种选若干个硬币,可以重复选同一种硬币, 使得(x1 + x2 + .... + xn) ^ 2 + (y1 + ...

  5. UVa 10306 - e-Coins

    题目:有m个钱币,有两种价值(xi,yi),现在要求组成面值sum(x)^2+sum(y)^2=s^2的最少硬币数. 分析:dp,二维安全背包.和以为背包相同,只是容量现在是二维的,按递增序枚举两个容 ...

  6. UVA 10306 e-Coins(二维完全背包)

    题意:e-coin有两个价值x,y,现在给你一个价值n,给你几种e-coin,问你能否用最小的e-coin数得到所求的价值n*n=(x1+x2+...xn)^2+(y1+y2+...yn)^2. 思路 ...

  7. uva 10306 e-coins【dp】

    二维完全背包 #include <bits/stdc++.h> #define cl(a) memset(a,0,sizeof(a)) #define rep(i,a,b) for(int ...

  8. UVa 10306. e-Coins

    题意为有m个向量,将任意个向量相加使得距离刚好为s,求向量的最小个数. 看题后的第一想法是用广搜+dp,后来提交代码却RE了(应该不会的).后来用枚举试了一下,还是RE.所以才想到是不是数组开小了一点 ...

  9. uva 10306 简单DP

    题意: 给n种硬币和一个面值s. 每种硬币有两种价值,并且有无限个,求能满足第一种价值i * i + j * j = s * s的最少硬币数. 解析: 先dp出每种情况下i,j用的最少银币,然后暴力搞 ...

最新文章

  1. 步步为营 .NET 设计模式学习笔记 十九、Chain of Responsibility(职责链模式)
  2. Java反射机制深入详解
  3. Spring JDBC-事务方法嵌套调用解读
  4. 反射获取空参数构造方法并运行
  5. 分析windows宿主机Ping不通linux虚拟机的其中一种情况
  6. sizeof是c语言的一种运算符,深入sizeof的使用详解
  7. php 查看扩展 代码,[扩展推荐] 使用 PHP Insights 在终端查看 PHP 项目代码质量
  8. 【2016年第3期】以大数据为核心 驱动智慧城市变革
  9. npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.com/@mlamp%2fuser-info-dropdo
  10. Android程序捕获未处理异常,处理与第三方方法冲突时的异常传递
  11. [leetcode] 4. 寻找两个有序数组的中位数
  12. 查询ORACLE数据库操作记录
  13. dx 汇编dec_汇编语言算术指令
  14. 达梦数据库导出、导入操作
  15. 处理器排行_2019年度PC处理器性能排行榜:AMD反超Intel
  16. 【 Laravel 工具包推荐--角色/权限管理】
  17. 苹果Mac安装win10双系统
  18. 计算机绘图中级,《计算机绘图中级教程》1.doc
  19. 深度揭秘腾讯云新一代企业级HTAP数据库TBase核心概念
  20. 大数据之Hadoop学习——动手实战学习MapReduce编程实例

热门文章

  1. 计算机中1 tb的硬盘容量大小等于,大脑记忆容量等于多大硬盘?
  2. 保护计算机组件免受esd,USB3.0接口的ESD防护设计
  3. 看了他家的红木装修,彻底被圈粉了,庄重典雅又复古舒适
  4. python 图灵机器人_图灵机器人 python 试玩
  5. app Token验证流程
  6. 【KNIME案例】参数化驱动工作流调用业务人员建立的脚本
  7. linux硬件测试拷机软件,“拷机”中。
  8. IT行业岗位以及发展方向
  9. 传统语音识别介绍【四】—— 语言模型
  10. C++-对于一个频繁使用的短小函数,应该使用什么来实现?有什么优缺点?