The first Central China Program Design Invitational competition and the tenth Wuhan University Program Design Competition Network preliminaries I (HDOJ-4223)

Source: Internet
Author: User

This question is DP? However, it is clear that the solution is not DP... for this class of question about finding a combination of intervals... You can first set each sum (1 ~ K) calculate... get the value of a certain range by the difference between the two sum... think of this step... the idea of this question comes out... calculate all sum (1 ~ K) <1 <= k <= n> .. sort sum .. find the smallest sum [I]-sum [I-1... but pay attention to it here .. for sum .. there should be n + 1 .. that is to add a sum [n + 1] = 0...

Program:

# Include <stdio. h> # include <iostream> # include <string. h> # include <math. h> using namespace STD; int t, t, a [1005], n, I, ans; int main () {freopen ("input.txt", "r", stdin ); freopen ("output.txt", "W", stdout); scanf ("% d", & T); For (t = 1; t <= T; t ++) {scanf ("% d", & N); for (I = 1; I <= N; I ++) scanf ("% d ", & A [I]); for (I = 2; I <= N; I ++) A [I] + = A [I-1]; A [+ N] = 0; sort (a + 1, A + 1 + n); ans = 200000; for (I = 2; I <= N; I ++) if (ANS> A [I]-A [I-1]) ans = A [I]-A [I-1]; printf ("case % d: % d \ n ", T, 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.