思路:dp[i][x][y]表示第i个序列中,右脚在x位置,左脚在y位置时,其最小花费。

那么dp[i][x][y]=min(dp[i-1][a[i]][y]+cost[a[i]][x],dp[i-1][x][a[i]]+cost[a[i]][y]);

题目连接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=32

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Maxn 2010
#define Maxm 100010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 0x7fffffff
#define Mod 1000000007
using namespace std;
int cost[][]={{,,,,},{,,,,},{,,,,},{,,,,},{,,,,}};
int dp[][][];
int list[];
int main()
{
int n,i,j,cnt,num,x,y;
cnt=;
while(scanf("%d",&list[++cnt]),list[cnt])
{
memset(dp,,sizeof(dp));
while(scanf("%d",&num)){
if(num!=) {
list[++cnt]=num;
continue;
}
dp[][list[]][]=cost[][list[]];
dp[][][list[]]=cost[][list[]];
for(i=;i<=cnt;i++){
for(x=;x<=;x++){
for(y=;y<=;y++){
dp[i][list[i]][y]=min(dp[i][list[i]][y],dp[i-][x][y]+cost[x][list[i]]);
dp[i][x][list[i]]=min(dp[i][x][list[i]],dp[i-][x][y]+cost[y][list[i]]);
}
}
}
int ans=inf;
for(i=;i<=;i++)
for(j=;j<=;j++)
ans=min(ans,dp[cnt][i][j]);
printf("%d\n",ans);
cnt=;
break;
}
}
return ;
}

2000 Asia shanghai Dance Dance Revolution的更多相关文章

  1. [LA] 2031 Dance Dance Revolution

    Dance Dance Revolution Time limit: 3.000 seconds Mr. White, a fat man, now is crazy about a game nam ...

  2. UVA 1291 十四 Dance Dance Revolution

    Dance Dance Revolution Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Su ...

  3. 递推DP UVA 1291 Dance Dance Revolution

    题目传送门 题意:给一串跳舞的动作,至少一只脚落到指定的位置,不同的走法有不同的体力消耗,问最小体力消费多少分析:dp[i][j][k] 表示前i个动作,当前状态(j, k)的最小消费,状态转移方程: ...

  4. Dance Dance Revolution

    今天我们来讲 Dance Dance Revolution这题 本题原网址 注意本题为多组输入输出,直到输入单个零而止(题面有点小问题) 很明显,此题为一道动态规划题(请不要妄想用贪心算法过这题,尽管 ...

  5. 【转帖】linux date 显示指定时区的时间 借助TZ 环境变量 export TZ=Asia/Shanghai 或 America/New_York

    linux date 显示指定时区的时间 借助TZ 环境变量 export TZ=Asia/Shanghai 或 America/New_York 2015-02-10 10:58:22 youcha ...

  6. 解决mysql设置时区时的错误Unknown or incorrect time zone: 'Asia/Shanghai'

    Mysql默认时区格式是'+8:00'的格式,这个时区可以在my.ini中[mysqld]节点下设置 default-time-zone = '+8:00' 默认这个设置是没有的 但是mysql不支持 ...

  7. 关于服务器时区BEIST-8、GMT-8、Asia/Shanghai、CST、GMT+8:00等缩写的含义

    http://www.talkwithtrend.com/Article/147961 AIX系统时区总结 字数 2078阅读 5844评论 0赞 0 前几天NTP的问题牵涉出时区问题,大家可能被眼花 ...

  8. .WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=UTF-8&;serverTimezone=Asia/Shanghai'.)

    连接mysql库报的异常信息: org.springframework.transaction.CannotCreateTransactionException: Could not open JDB ...

  9. The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)

    The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/ ...

随机推荐

  1. Window.navigator

    定义和用法 userAgent 属性是一个只读的字符串,声明了浏览器用于 HTTP 请求的用户代理头的值. 一般来讲,它是在 navigator.appCodeName 的值之后加上斜线和 navig ...

  2. Javascript模块规范(CommonJS规范&&AMD规范)

    Javascript模块化编程(AMD&CommonJS) 前端模块化开发的价值:https://github.com/seajs/seajs/issues/547 模块的写法 查看 AMD规 ...

  3. Jquery基础:append、prepend、after、before、appendTo的区别

    append() 是在被选元素的结束标签前面(即改被选元素的内部)插入指定内容. after() 是在被选元素的结束标签后面(即该被选元素的外部)插入指定的内容. appendTo() 仍然是在被选元 ...

  4. CSS(04) 定位

    布局常用的三种:标准流.定位.浮动: 1.文档流-标准流 窗体自上而下分成一行行(元素在 (X)HTML 中的位置),并在一行行中从左到右排放元素: 2.CSS 定位 Position 属性(绝对定位 ...

  5. 理解Web标准(网站标准)

    我觉得一名Web前端应该好好理解Web标准到底是什么,为什么要在我们的实际实践中遵循Web标准. 什么是Web标准.百度百科的解释是: WEB标准不是某一个标准,而是一系列标准的集合.网页主要由三部分 ...

  6. IAR EWARM PRINTF/SCANF FORMATTER

    The linker automatically chooses an appropriate formatter for printf- and scanf-related function bas ...

  7. HTTP状态码通常分为5种类型

    HTTP状态码通常分为5种类型,分别以1-5五个数字开头,由3位整数组成: -------------------------------------------------------------- ...

  8. Java *字格

    class XingDemo { public static void main(String[] args) { int j = 0; int i = 0; int k = 0; for(i = 0 ...

  9. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  10. acdream 1738 世风日下的哗啦啦族I 分块

    世风日下的哗啦啦族I Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acdream.info/problem?pid=1738 Descri ...