"Hduoj" several recursive DP

Source: Internet
Author: User

You don't have to write a puzzle. Very basic recursion.

HDU2084 Number Tower

title Link:http://acm.hdu.edu.cn/showproblem.php?pid=2084

Code:

1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5 6 using namespacestd;7 Const intMAXN = the;8 9 intDP[MAXN][MAXN];Ten intA[MAXN][MAXN]; One  A intMain () { -     intT; -Cin>>T; the      while(t--){ -Memset (A,0,sizeof(a)); -Memset (DP,0,sizeof(DP)); -         intN; +Cin>>N; -          for(inti =1; I <= N; i++){ +              for(intj =1; J <= I; J + +){ ACin>>A[i][j]; at             } -         } -  -          for(inti = n; i >0; i--){ -              for(intj =1; J <= N; j + +){ -DP[I][J] = max (dp[i+1][J], dp[i+1][j+1]) +A[i][j]; in             } -         } tocout<<dp[1][1]<<Endl; +     } -  the  *     return 0; $}

The story of the HDU2018 cow

title link : http://acm.hdu.edu.cn/showproblem.php?pid=2018

Code:

1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5 6 using namespacestd;7 Const intMAXN = the;8 intDP[MAXN];9 Ten voidinit () { Onedp[1] =1; Adp[2] =2; -dp[3] =3; -dp[4] =4; thedp[5] =6; -      for(inti =6; I <= -; i++){ -Dp[i] = dp[i-1] + dp[i-3]; -     } + } -  + intMain () { A     intN; at init (); -      while(Cin>>n &&N) { -cout<<dp[n]<<Endl; -     } -  -     return 0; in}

HDU2044 the story of the Little Bee

Same type HDU2041

title Link:http://acm.hdu.edu.cn/showproblem.php?pid=2044

Code:

1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5 #definell Long Long6 using namespacestd;7 Const intMAXN = -;8 ll FIB[MAXN];9 Ten voidinit () { Onefib[0] =0; Afib[1] =1; -fib[2] =2; -      for(inti =3; I <= maxn; i++){ theFib[i] = fib[i-1] + fib[i-2]; -     } - } -  + intMain () { - init (); +     intn,m; A     intT; atCin>>T; -      while(t--){ -Cin>>n>>m; -cout<<fib[m-n]<<Endl; -     } -  in  -     return 0; to}

HDU2050

title Link:http://acm.hdu.edu.cn/showproblem.php?pid=2050

Code:

1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5 #definell Long Long6 using namespacestd;7 Const intMAXN =10005;8 ll DP[MAXN];9 Ten voidinit () { Onedp[1] =2; Adp[2] =7; -      for(inti =3; I <= MAXN; i++){ -Dp[i] = dp[i-1] +4* (I-1) +1; the     } - } -  - intMain () { +     intT; -Cin>>T; +     intN; A init (); at      while(t--){ -Cin>>N; -cout<<dp[n]<<Endl; -     } -  -     return 0; in}

"Hduoj" several recursive DP

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.