Dividing 03多重背包问题


http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1005&ojid=0&cid=3900

Dividing

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 2
Problem Description
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value.
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.


 

Input
Each line in the input describes one collection of marbles to be divided. The lines consist of six non-negative integers n1, n2, ..., n6, where ni is the number of marbles of value i. So, the example from above would be described by the input-line ``1 0 1 2 0 0''. The maximum total number of marbles will be 20000.

The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.


 

Output
For each colletcion, output ``Collection #k:'', where k is the number of the test case, and then either ``Can be divided.'' or ``Can't be divided.''.

Output a blank line after each test case.


 

Sample Input
  
  
1 0 1 2 0 0 1 0 0 0 1 1 0 0 0 0 0 0


 

Sample Output
  
  
Collection #1: Can't be divided. Collection #2: Can be divided.
 
用到n[i]=n[i]%10; mod10 跟以前的情况就会是一致的
否则的话就会超时
 
 

 

#include<cstdio>
#include<cstring>
using namespace std;
int dp[60500];
int main()
{
    int n[7];
    int v[7];
    int sum=0;
    int test=1;
    while(scanf("%d",&n[1])!=EOF)
    {
        memset(dp,0,sizeof(dp));
        int sum=n[1];
        int t;
        for(int i=2; i<=6; i++)
        {
            scanf("%d",&t);
            n[i]=t%10;
            sum+=i*n[i];
        }

        if(n[1]==0&&n[2]==0&&n[3]==0&&n[4]==0&&n[5]==0&&n[6]==0)  break;
        if(sum%2==1)
        {
            printf("Collection #%d:\nCan't be divided.\n\n",test);
            test++;
            continue;
        }
        for(int i=1; i<=6; i++)
            v[i]=i;
        int V=sum/2;
        dp[0]=1;
        for(int i=1; i<=6; i++)
        {
            for(int j=0; j<n[i]; j++)
            {
                for(int k=V; k>=v[i]; k--)
                {
                    if(dp[k-v[i]])
                        dp[k]=1;
                }
            }
        }
       // for(int i=V;i>=0;i--)
        //printf("%d   %d\n",dp[i],i);
        if(dp[V]==1)
        {
            printf("Collection #%d:\nCan be divided.\n\n",test);
            test++;
        }
        else
        {
            printf("Collection #%d:\nCan't be divided.\n\n",test);
            test++;
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
随着人口老龄化和空巢化等社会问题的日益严峻,养老问题及以及养老方式的变革成为了当前社会的发展焦点,传统的养老模式以救助型和独立型为主,社会养老的服务质量与老年人的养老需求还存在一定的差距,人们生活水平的提高以及养老多元化需求的增加都需要通过创新和灵活开放的养老模式来应对未来的养老需求,结合目前我国养老模式及养老服务问题的内容的分析,互助养老模式作为一种新型的养老模式结合自主互助的集体养老理念,帮助老年人实现了满足个性需求的养老方案,互助养老模式让老年人具备了双重角色的同时也实现可持续的发展特色。目前我国老年人的占比以每年5%的速度在飞速增长,养老问题及养老服务的提供已经无法满足当前社会养老的切实需求,在养老服务质量和养老产品的变革过程中需要集合多元化的养老模式来满足更多老人的养老需求。 鉴于我国目前人口老龄化的现状以及迅速扩张的养老服务需求,现有的养老模式已经无法应对和满足社会发展的需求,快速增长的养老人员以及养老服务供给不足造成了紧张的社会关系,本文结合当前养老服务的发展需求,利用SSM框架以及JSP技术开发设计一款正对在线互助养老的系统,通过系统平台实现养老机构信息的传递及线上预约,搭建了起了用户、养老机构以及系统管理员的三方数据平台,借助网页端实现在线的养老互助信息查询、养老机构在线预约以及求助需求等功能,通过自养互养的养老模式来帮助老年人重新发现自我价值以及丰富养老的主观能动性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值