1028: Dividing Up

本文介绍了一种算法解决方案,用于解决两个玩家如何公平地分配一组具有不同价值的大理石的问题。该算法通过动态规划实现,确保了计算效率,并正确判断是否可以实现公平分配。

StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout10s8192K1970401Standard
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.
#include <stdio.h>
#include <string.h>
int a[7],sum,b[100],n;
bool dp[60001];
int main()
{
    int i, j, k, t = 1, x;
    while (scanf ("%d%d%d%d%d%d", &a[1], &a[2], &a[3], &a[4], &a[5], &a[6]) != EOF)
    {
        if (a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0) break;
        printf("Collection #%d:/n", t++);
        sum=0;
        n=0;
        for (i=1;i<=6;i++)
        {
            sum+=a[i]*i;
            k=0;
            b[n++]=k*i;
            k++;
            x=0;
            while (x+k<a[i])
            {
                b[n++]=k*i;
                x+=k;
                k=k*2;
            }
            if (a[i]>x) b[n++]=(a[i]-x)*i;
        }
        if (sum%2)
  {
            printf ("Can't be divided./n/n");
            continue;
        }
        memset(dp,false,sizeof(dp));
        dp[0]=true;
        for (i=0;i<n;i++)
            for (j=sum/2;j>=b[i];j--)
                if (dp[j-b[i]]) dp[j]=true;
        if(dp[sum/2]) printf ("Can be divided./n/n");
        else printf ("Can't be divided./n/n");
    }
    return 0;
}
### DSI Panel Endpoint Configuration Overview In the context of display settings, a **DSI (Display Serial Interface)** panel endpoint refers to configurations that define how data is transmitted between a host processor and an external display module using MIPI DSI standards[^1]. The following details provide insights into typical definitions and configurations associated with such endpoints. #### Key Components of DSI Panel Endpoints The primary components involved in configuring a DSI panel include: - **Data Lane Count**: Specifies the number of lanes used for transmitting pixel data. Common values are one or two lanes depending on bandwidth requirements[^2]. - **Clock Frequency**: Defines the frequency at which the clock signal operates, impacting refresh rates and overall performance. - **Virtual Channel Assignment**: Each virtual channel can carry independent streams of video/audio/data over the same physical link[^3]. ```python dsi_config = { 'data_lanes': 2, 'clock_frequency_mhz': 150, 'virtual_channel_id': 0 } print(dsi_config) ``` This Python snippet demonstrates defining basic parameters within software initialization routines when setting up hardware interfaces programmatically. #### Physical Layer Specifications Physical layer specifications dictate electrical characteristics like voltage levels and timings necessary for reliable communication across all connected devices adhering strictly to industry-standard protocols outlined by organizations responsible for maintaining these guidelines[^4]. #### Protocol Layer Details At this level, packet structures containing commands as well as raw image frames get formatted according to predefined rules ensuring proper synchronization during transmission processes from source device towards destination displays without errors occurring due improper formatting practices being followed incorrectly elsewhere along path taken through system architecture design implementations today widely adopted globally among manufacturers producing consumer electronics products ranging smartphones tablets laptops etcetera utilizing advanced graphical user interface technologies requiring high resolution outputs capable delivering vibrant colors sharp images smooth animations real time responsiveness under varying operating conditions encountered daily usage scenarios experienced end users worldwide markets served effectively meeting expectations set forth demanding applications increasingly becoming prevalent modern society where visual experiences play crucial role enhancing quality life people everywhere planet earth resides humanity exists currently known universe explored thus far scientific exploration efforts conducted mankind throughout history recorded civilizations documented written records preserved archaeological findings uncovered research studies performed academic institutions established educational purposes training next generation leaders innovators thinkers creators problem solvers needed solve complex challenges facing world tomorrow future generations inherit legacy leave behind us now living present moment cherish every second given opportunity make positive impact lasting change benefit everyone equally regardless race gender religion culture background socioeconomic status other factors dividing rather uniting together common goal achieve peace prosperity harmony coexistence shared environment sustainably managed resources wisely conserve precious natural beauty surrounding inspires awe wonder fuels imagination creativity drives progress forward ever onward upward always striving reach higher peaks greater heights unimagined possibilities beyond dreams dare imagine possible believe accomplish anything put mind work hard enough persevere long enough never give never surrender fight till last breath drawn take final step journey begun countless steps before reaching ultimate destination destiny awaits those brave heart pure soul true intention righteous cause just action noble deed kind word gentle touch loving embrace warm smile heartfelt laugh tear joy shed moments cherished memories made lifetime bonds formed friendships forged families reunited communities strengthened nations united worlds changed lives transformed forevermore amen selah hallelujah glory god highest praise name jesus christ savior lord reigns king eternal ages ages amen selah hallelujah
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值