多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > UVA 10306 e-Coins(二維完全背包)

UVA 10306 e-Coins(二維完全背包)

來源:程序員人生   發布時間:2014-12-13 09:28:15 閱讀次數:3299次

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 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



2維背包:題意:兩個屬性x,y,求最少的數使(x1+x2+.xk)^2+(y1+y2+..yk)^2=s*s;

斟酌背包:dp[i][j]表示屬性為i,j的時候數。

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> typedef long long LL; using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) const int INF=0x3f3f3f3f; const int maxn=330; int dp[maxn][maxn]; int w1[55],w2[55]; int t,n,s; int main() { std::ios::sync_with_stdio(false); cin>>t; while(t--) { cin>>n>>s; CLEAR(dp,INF); dp[0][0]=0; REP(i,n) cin>>w1[i]>>w2[i]; REP(i,n) { REPF(j,w1[i],s) { REPF(k,w2[i],s) { if(dp[j-w1[i]][k-w2[i]]!=INF) dp[j][k]=min(dp[j][k],dp[j-w1[i]][k-w2[i]]+1); } } } int ans=INF; REPF(i,0,s) { REPF(j,0,s) { if(dp[i][j]!=INF&&i*i+j*j==s*s) ans=min(ans,dp[i][j]); } } if(ans!=INF) cout<<ans<<endl; else cout<<"not possible"<<endl; } return 0; }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 精品无码久久久久久国产 | 亚洲国产成人在线视频 | 一级特黄特黄毛片欧美的 | 美女教师一级毛片 | 国内自拍视频网站 | 亚洲 欧美 日韩在线 | 免费一级毛片在线视频观看 | www.日韩精品| 最近中文国语字幕 | 久久久久久极精品久久久 | 日韩欧美久久一区二区 | 欧美成人一区二区三区不卡视频 | 日韩中文字幕一区二区不卡 | 欧美精品综合 | 一区二区三区国产 | 毛片一级在线观看 | 在线免费激情视频 | 图片区小说区激情区偷拍区 | 久久本网站受美利坚法律保护 | 免费国产成人α片 | 最近中文字幕mv免费高清视频免费 | 欧美色精品 | 四虎东方va私人影库在线观看 | 亚洲成av人片在线观看 | 久久久精品国产免费观看同学 | 一区二区三区视频在线观看 | 国产成人精品亚洲一区 | 国产毛片a级 | 国产成人高清精品免费5388密 | www 在线播放| 亚洲精品一二三四区 | 欧美韩一级片 | 亚洲第一综合网站 | 69热视频| 欧美成人性色 | www.中文字幕在线 | 秋霞网站一级一片 | jizz亚洲| 吃奶添下面大尺度视频 | 国产欧美一区二区三区久久 | 日本一区二区三区在线 视频观看免费 |