HDU 2844 Coins(二进制优化)

  • -

Coins

题目链接

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16702 Accepted Submission(s): 6634

Problem Description
Whuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the price would not more than m.But he didn’t know the exact price of the watch.

You are to write a program which reads n,m,A1,A2,A3…An and C1,C2,C3…Cn corresponding to the number of Tony’s coins of value A1,A2,A3…An then calculate how many prices(form 1 to m) Tony can pay use these coins.

Input
The input contains several test cases. The first line of each test case contains two integers n(1 ≤ n ≤ 100),m(m ≤ 100000).The second line contains 2n integers, denoting A1,A2,A3…An,C1,C2,C3…Cn (1 ≤ Ai ≤ 100000,1 ≤ Ci ≤ 1000). The last test case is followed by two zeros.

Output
For each test case output the answer on a single line.

Sample Input
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0


Sample Output
8
4


Source
2009 Multi-University Training Contest 3 - Host by WHU
///题意:有一些被划分为1-6价值的石头,并一直每个价值有多少块,求可否将石头分成两份且价值相等。
///思路:求出总价值,除2。转化为大小为(总价值/2)的背包可否恰好装满的问题。
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int dp[100050];
const int inf=0x3f3f3f3f;
int main()
{
    int a[15],b[15],st[1040];
    int t=1;
    while(1)
    {
        int sum=0;
        for(int i=0;i<6;i++)
            scanf("%d",&a[i]),sum+=a[i];
        if(sum==0)
            break;
        sum=0;
        for(int i=0;i<6;i++)
        {
            sum+=a[i]*(i+1);//求总和  
            b[i]=i+1;
        }
        printf("Collection #%d:\n",t++);
        if(sum%2==1)
        {
            printf("Can't be divided.\n\n"); //总和是奇数则不能平分 
            continue;
        }
        int num=sum/2;
        memset(dp,0,sizeof(dp));
        int to=0;
        for(int i=0;i<6;i++)
        {
            if(a[i]==0) continue;
            int te=1;
            while(a[i]>te)
            {
                st[to++]=te*b[i];//将新的值赋给st[]  
                a[i]-=te;
                te*=2;//二进制压缩为——01背包  
            }
            st[to++]=a[i]*b[i];
        }
        for(int i=0;i<to;i++)//01背包
        {
            for(int j=num;j>=st[i];j--)
                dp[j]=max(dp[j],dp[j-st[i]]+st[i]);
        }
        if(dp[num]==num)
            printf("Can be divided.\n\n");
        else
            printf("Can't be divided.\n\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Eclipse二进制文件是指由Eclipse集成开发环境生成的可执行文件。在Linux下,Eclipse生成的二进制文件通常是没有扩展名的,如上述引用所示。在使用Eclipse编译和运行项目时,如果项目名包含扩展名(例如.hdu.c),则Eclipse可能无法正确识别该文件为二进制可执行文件。 这可能导致在运行时出现找不到二进制文件的错误。解决办法有两种:一是避免使用带有扩展名的项目名,另一种是手动创建一个运行配置,将命令写死以确保正确识别为二进制文件。 需要注意的是,上述讨论中的EclipseParser库是一个用于验证和读取Eclipse二进制文件内容的DLL库,它是通过按照二进制格式编写的。这个库可以验证和读取Eclipse二进制文件中的EGRID、INIT、UNRST等内容。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [linux下eclipse c++运行不了提示找不到二进制文件的解决方法](https://blog.csdn.net/bjrxyz/article/details/8974483)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Eclipse油藏数值模拟软件的二进制文件格式解析](https://blog.csdn.net/slofslb/article/details/119176891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值