HDU 5800 to My girlfriend

Source: Internet
Author: User

Title: To My Girlfriend

Links:http://acm.hdu.edu.cn/showproblem.php?pid=5800

Test instructions

Give you n, S, next n number, define F (i, J, K, L, m) to indicate the required for subscript I, J, K, L, and a subset of M.

  

  Then the value of the equation is calculated.

Ideas:

Just beginning to think of the number of I and less than equal to a subset of S, defined dp[i][j] represents the number of I, and the case of J, no matter how optimized or dead to n^3 level. Read the puzzle, only awakened ...

Definition DP[I][J][II][JJ] means: The number of the first I, and to achieve the j,ii required, JJ a must not select the case quantity. II, JJ Range is 0-2, four-cycle can be.

Divided into two types:

1. The number of I may not be selected, then DP[I][J][II][JJ] + + DP[I-1][J][II][JJ] + DP[I-1][J-A[I]][II][JJ].

2. There are two types of:

1. The number of I must be selected, DP[I][J][II][JJ] + = DP[I-1][J-A[I]][II-1][JJ].

2. The number of I must not be selected, DP[I][J][II][JJ] + = dp[i-1][j][ii][jj-1].

AC Code:

1#include <stdio.h>2#include <string.h>3 #defineMod 10000000074typedefLong LongLL;5 inta[1010];6 intdp[1010][1010][3][3];7 voidAddint&x,inty)8 {9x=x+y;Ten   if(X>=mod) x-=Mod; One } A intMain () - { -   intt,n,m; thescanf"%d",&t); -    while(t--) -   { -scanf"%d%d",&n,&m); +      for(intI=1; i<=n;i++) scanf ("%d",&a[i]); -Memset (DP,0,sizeof(DP)); +dp[0][0][0][0]=1; A      for(intI=1; i<=n;i++) at     { -        for(intj=m;j>=0; j--) -       { -          for(intIi=2; ii>=0; ii--) -         { -            for(intjj=2; jj>=0; jj--) in           { -Add (DP[I][J][II][JJ], dp[i-1][J][II][JJ]); to             if(j+a[i]<=m) Add (DP[I][J+A[I]][II][JJ], dp[i-1][J][II][JJ]); +             if(ii >0&& j+a[i]<=m) Add (DP[I][J+A[I]][II][JJ], dp[i-1][j][ii-1][JJ]); -             if(JJ >0) Add (DP[I][J][II][JJ], dp[i-1][j][ii][jj-1] ); the           } *         } $       }Panax Notoginseng     } -LL ret=0; the      for(intI=2; i<=m;i++) +     { Aret=ret+dp[n][i][2][2]; the     } +printf"%i64d\n", ret*2*2%Mod); -   } $   return 0; $}

HDU 5800 to My girlfriend

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.