HDU 5000 clone (Anshan Network Competition D)

Source: Internet
Author: User
HDU 5000 clone

There are three questions in this case .. I am stuck on this question. Fortunately, I have saved my quota.

Idea: when the maximum value is introduced, each person's attributes must be the same, and this and must be all and/2. In this case, the problem is converted to N numbers, to combine the sum/2 methods, you can use the DP backpack to push it again.

Sum/2 was not introduced at the scene.

Code:

#include <cstdio>#include <cstring>const int MOD = 1000000007;const int N = 2005;int t, n, dp[N], T[N];int main() {scanf("%d", &t);while (t--) {scanf("%d", &n);int sum = 0;for (int i = 1; i <= n; i++) {scanf("%d", &T[i]);sum += T[i];}sum /= 2;memset(dp, 0, sizeof(dp));dp[0] = 1;for (int i = 1; i <= n; i++) {for (int k = sum; k >= 0; k--) {for (int j = 1; j <= T[i]; j++) {if (k - j < 0) break;dp[k] = (dp[k] + dp[k - j]) % MOD;}}}printf("%d\n", dp[sum]);}return 0;}


HDU 5000 clone (Anshan Network Competition D)

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.