HDU 5000 clone)

Source: Internet
Author: User

Address: HDU 5000

At that time, I had this idea, that is, the attributes and values of all satisfied situations are certain. However, the number of solutions is not calculated .. (Too weak ...) At that time, I was not sure whether the guess was correct .. So I put it down... After learning about DP, find the number of solutions.

As for the guess, I cannot prove it, but I personally think that only when the sum is equal can we maintain at least one larger value by increasing or decreasing a certain number, there is at least one small one, and if it is different, one of them will eliminate the other. Therefore, the number of solutions is the largest when sum is used. Obviously, we can guess that it's half the same (it won't prove it too... If you cannot see it, you can directly find the maximum value ).

The Code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int madan[3000][3000], ruo[3000];const int mod=1e9+7;int main(){    int ca, i, j, k, n, sb, ben;    scanf("%d",&ca);    while(ca--)    {        scanf("%d",&n);        sb=0;        for(i=1;i<=n;i++)        {            scanf("%d",&ruo[i]);            sb+=ruo[i];        }        memset(madan,0,sizeof(madan));        madan[0][0]=1;        ben=0;        for(i=0;i<n;i++)        {            for(j=0;j<=ben;j++)            {                if(!madan[i][j]) continue ;                for(k=0;k<=ruo[i+1];k++)                    {                        madan[i+1][j+k]+=madan[i][j];                        madan[i+1][j+k]%=mod;                    }            }            ben+=ruo[i+1];        }        printf("%d\n",madan[n][sb/2]);    }    return 0;}


HDU 5000 clone)

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.