# Uvalive 2031Dance Dance Revolution

Source: Internet
Author: User

Exercises

Simple DP

Dp[i][j][k] represents the position of step I feet in position J and position K

And then you can push the transfer equation according to test instructions.

Code:

`#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1#definePII pair<int,int>#definell Long LongConst intINF =1e9;Const intMAXN =50050; Vector<int>v;intx;intdp[MAXN [5][5 ];intStep_num (intSinte) {    if(s = =0)return 2; if(s = =1 )    {        if(E = =1)return 1; if(E = =2|| E = =4)return 3; if(E = =3)return 4; }    if(s = =2 )    {        if(E = =2)return 1; if(E = =1|| E = =3)return 3; if(E = =4)return 4; }    if(s = =3 )    {        if(E = =3)return 1; if(E = =2|| E = =4)return 3; if(E = =1)return 4; }    if(s = =4 )    {        if(E = =4)return 1; if(E = =1|| E = =3)return 3; if(E = =2)return 4; }}intMain () { while(~SCANF ("%d", &x) &&x) {v.clear ();        V.push_back (x);  while(SCANF ("%d", &x) &&x) v.push_back (x);  for(inti =0; I <5; i + + )         for(intj =0; J <5; J + + )         for(intK =0; K <50000; K + +) dp[k [i] [j] =INF; intn = v.size (), Goal =INF; dp[1][0[v[0]] = dp[1[v[0] ][0] =2;  for(inti =2; I <= N; i + + )        {            intnow = v[I-1 ];  for(intj =0; J <5; J + + )             for(intK =0; K <5; K + + )            {                if(j = k)Continue; if(J! = Now) dp[I [j] [Now] = min (dp[I [j] [now], dp[i-1[j] [K] +Step_num (k, now)); if(k! = Now) dp[I [now] [k] = min (dp[i] [now] [K], dp[i-1[j] [K] +Step_num (J, now)); if(i = =N) {goal=min (goal, dp[I [now] [K]); Goal=min (goal, dp[I [j] [now]); }}} printf ("%d\n", goal); }    return 0;}`

Uvalive 2031Dance Dance Revolution

Related Keywords:

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.