Recursive DP UVA 1291 Dance Dance Revolution

Source: Internet
Author: User

Topic Portal

1 /*2 Test instructions: Give a string of dancing action, at least one foot falls to the specified position, different walking methods have different physical exertion, ask the minimum physical consumption of how much3 Dp:dp[i][j][k] Represents the minimum consumption of the first I action, the current state (J, K), the state transition equation: (a[i], k) <-min (a[i-1], K) + cost4 and (A[i-1], a[i]) <-min (a[i-1], K) + Cost, (K, A[i]) and (A[i], a[i-1]) The situation is similar, and finally the minimum value is OK.5 */6 /************************************************7 * Author:running_time8 * Created time:2015-8-15 14:31:319 * File Name:UVA_1291.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 = 1e4 +Ten; * Const intINF =0x3f3f3f3f; $ Const intMOD = 1e9 +7;Panax Notoginseng intA[MAXN]; - intdp[maxn][5][5]; the  + intCalintXinty) { A     intret; the     if(x = = y) ret =1; +     Else    { -         if(Y = =0) ret =2; $         Else    { $             if(ABS (x-y) = =2)   { -RET =4; -             } the             ElseRET =3; -         }Wuyi     } the     returnret; - } Wu  - intMainvoid)    {//UVA 1291 Dance Dance Revolution About     intn =0; $      while(SCANF ("%d", &a[++n]) = =1)  { -         if(a[1] ==0) Break; -          while(A[n]! =0)   { -scanf ("%d", &a[++n]); A         } +n--; theMemset (DP, INF,sizeof(DP)); -dp[1][a[1]][0] = (a[1] ==0?1:2); $dp[1][0][a[1]] = (a[1] ==0?1:2); the          for(intI=2; i<=n; ++i) { the              for(intj=0; j<=4; ++j) { the                 intC1 =Cal (A[i], j); the                 intC2 = Cal (A[i], a[i-1]); -                 intx = A[i], y = a[i-1]; inDp[i][x][y] = min (Dp[i][x][y], dp[i-1][j][y] +C1); theDp[i][j][x] = min (dp[i][j][x], dp[i-1][j][y] +C2); the  AboutDp[i][y][x] = min (dp[i][y][x], dp[i-1][Y][J] +C1); theDp[i][x][j] = min (dp[i][x][j], dp[i-1][Y][J] +C2); the             } the         } +  -         intAns =INF; the          for(intI=0; i<=4; ++i) {BayiAns =min (ans, min (Dp[n][i][a[n]], dp[n][a[n]][i])); the         } theprintf ("%d\n", ans); n =0; -     } -  the     return 0; the}

Recursive DP UVA 1291 Dance Dance Revolution

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.