最新公告
  • 欢迎您光临波比源码,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入我们
  • UVA 10306 e-Coins(二维完全背包)

    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.bobi11.com
    1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
    2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
    3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
    4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
    5. 如有链接无法下载、失效或广告,请联系管理员处理!
    6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
    7. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

    波比源码 » UVA 10306 e-Coins(二维完全背包)

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    波比源码
    一个高级程序员模板开发平台
    升级波友尊享更多特权立即升级