Poj 3782 Equal Sum Partitions

Source: Internet
Author: User

Poj 3782 Equal Sum Partitions

Question:

For a sequence, divide it into several sub-sequences that are equal to each other to obtain the possible minimum sum.

Analysis:

The brute force enumeration is good, and the data is weak.

Code:

// Poj 3782 // sep9 # include <iostream> using namespace std; const int maxN = 10024; int a [maxN], n; int test (int mid) {int I, sum = 0; for (I = 1; I <= n; ++ I) {sum + = a [I]; if (sum = mid) sum = 0; else if (sum <mid) continue; elsereturn 0;} if (sum! = 0) return 0; return 1;} int main () {int cases, cases_num, ans; scanf ("% d", & cases); while (cases --) {int I, sum = 0; scanf ("% d", & cases_num, & n); for (I = 1; I <= n; ++ I) {scanf ("% d", & a [I]); sum + = a [I] ;}for (I = 0; I <= sum; ++ I) if (test (I) = 1) {ans = I; break;} printf ("% d \ n", cases_num, ans);} return 0 ;}



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.