Recursive DP hdoj 5389 Zero Escape

Source: Internet
Author: User

Topic Portal

1 /*2 Test Instructions: The n number is divided into two groups, a group of add up is a, a group of add up is b,1<=a,b<=9, can also be all divided into the same group. The addition is in accordance with the rules he gives, is a plus, more than one digit to split into a plus. 3 Dp:dp[i][j] Records the sum of the number of previous I and the program number of J, then the state transfer equation: dp[i][j+a[i]] + = dp[i-1][j]; Of course, dp[i][a[i]] = 1;4 then consider several special cases: go to S1 Gate or S2 Gate, plan number +1. In addition, the game I wrote the correct transfer equation, the answer output DP[N][S1]+DP[N][S2] nearly twice times, did not think, abandoned, when the mind is very chaotic, think the method is wrong .... 5 */6 /************************************************7 * Author:running_time8 * Created time:2015-8-13 14:39:589 * File name:j.cppTen  ************************************************/ One  A#include <cstdio> -#include <algorithm> -#include <iostream> the#include <sstream> -#include <cstring> -#include <cmath> -#include <string> +#include <vector> -#include <queue> +#include <deque> A#include <stack> at#include <list> -#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> in using namespacestd; -  to #defineLson L, Mid, RT << 1 + #defineRson mid + 1, R, RT << 1 | 1 -typedefLong Longll; the Const intMAXN = 1e5 +Ten; * Const intINF =0x3f3f3f3f; $ Const intMOD =258280327;Panax Notoginseng intdp[maxn][Ten]; - intA[MAXN]; the intN, s1, S2; +  A intCalintXinty) { the     intRET = x +y; +RET%=9; -     if(ret = =0)return 9; $     Else    returnret; $ } -  - intMainvoid)    {//hdoj 5389 Zero Escape the     intT scanf ("%d", &T); -      while(t--) {Wuyiscanf ("%d%d%d", &n, &AMP;S1, &S2); the         intsum =0; -          for(intI=1; i<=n; ++i) {//add up the n number and then follow the rules and the two two plus are the same. Wuscanf ("%d", &a[i]); sum =cal (SUM, a[i]); -         } About  $Memset (DP,0,sizeof(DP)); -          for(intI=1; i<=n; ++i) { -Dp[i][a[i]] =1; -              for(intj=9; j>=0; --j) { ADP[I][J] = (Dp[i][j] + dp[i-1][J])%MOD; +                 if(j + A[i] >9)   { the                     intx =Cal (J, A[i]); -DP[I][X] = (Dp[i][x] + dp[i-1][J])%MOD; $                 } the                 Else    { theDp[i][j+a[i]] = (Dp[i][j+a[i]] + dp[i-1][J])%MOD; the                 } the             } -         } in  the         intAns =0; the         if(Cal (S1, s2) = = SUM) {//two doors can go in and meet the conditions . AboutAns + =DP[N][S1]; the             if(S1 = = sum) ans--; the         } the         if(S1 = = sum) ans++;//you can go all the door . +         if(S2 = = sum) ans++; -  theprintf ("%d\n", ans);Bayi     } the  the     return 0; -}

Recursive DP hdoj 5389 Zero Escape

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.