Poj 1014 dividing

Source: Internet
Author: User

The feasibility of multiple backpacks.


Meaning 1 ~ 6 stones worth 1 ~ 6. Then there are different quantities and you can ask if you can evenly distribute them to two people.


At this time, we can regard the value as a cost, and find out if we can reach half of the total value. That is to say, if the capacity of a backpack is set to half of the total value, can it be full.


It is said that there is a very powerful "cut tree" 1 ~ The minimum public factor of 6 is 60.

More than 60 ...... If (N & 1) n = 61; else n = 60;

Orz ...... I did not expect this.


# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <queue> # include <map> # include <stack> # include <iostream> # include <list> # include <set> # include <cmath> # define INF 0x7fffffff # define EPS 1e-6 # define ll long longusing namespace STD; int n, m; int DP [7] [150001]; int cot [7]; int cost [7]; int main () {int cc = 1; while (1) {bool flag = 1; M = 0; For (INT I = 1; I <7; I ++) {int TMP; scanf ("% d", & TMP ); if (TMP) Flag = 0; cost [I] = I, Cot [I] = TMP; m + = cost [I] * cot [I];} If (FLAG) return 0; memset (DP,-1, sizeof (DP); printf ("collection # % d: \ n", CC ++); If (M & 1) {puts ("can't be divided. \ n "); continue;} else M/= 2; DP [0] [0] = 0; For (INT I = 1; I <7; I ++) {for (Int J = 0; j <= m; j ++) {If (DP [I-1] [J]> = 0) DP [I] [J] = cot [I]; else DP [I] [J] =-1;} For (Int J = 0; j <= m-cost [I]; j ++) {If (DP [I] [J]> 0) DP [I] [J + cost [I] = max (DP [I] [J + cost [I], DP [I] [J]-1) ;}} if (DP [6] [m] =-1) puts ("can't be divided. \ n "); else puts (" can be divided. \ n ");}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.