hdu 3561 Dp

A Simple Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 464    Accepted Submission(s): 189


Problem Description
There's one row of buttons lying on onmylove's laptop keyboard, which are used to input the numbers,just as shown in the picture:



onmylove used to input the numbers with his two specifc fingers,, one is on the left, the other is on the right. In one unit time, onmylove's two fingers can both operate. For each finger, each operation can be one of the following:
1.press on the button just under the finger.
2.move to the left button or the right button.

But there're still some points you should pay attention to:
1. at any time, the left nger should at the left side of the right finger.
2. in one unit of time, only one of these two fingers can press the button under it. Of course, the other
finger can move at this unit of time.

Now you are given a string which consists of only numbers, you are asked to calculate: if onmylove want to input all these numbers, how many time does he need at least? At the every beginning, the left finger is above the button "5" and the right finger is above the button "6".
 

Input
Multiple inputs. For each test case, there is one string at a line. It's promised there're only numbers in the string and the length of it is not more than 100.
 

Output
For each test case, output one number at a line, which represents the least time you need.
 

Sample Input
 
   
434 56 57 47
 

Sample Output
 
   
5 2 2 3
 

Author
onmylove
 

Source
2010 Asia Regional Chengdu Site —— Online Contest
 

Recommend
lcy
 

#include 
#include 
#include 
#define inf 0x3f3f3f3f
#define bug printf("asfd")
using namespace std;
char word[105];
int num[105];
int dp[2][15][15];
int pre,cur;
inline int abs(int x)
{
    if(x>=0)
        return x;
    else
        return -x;
}
void lefthand(int pos,int x,int y)
{
    if(pos==10)
        return ;
    int dis=abs(pos-x)+1;
    int i;
    for(i=0;i<=dis&&y+i<=10;i++)
    {
        if(y+i>pos)
            dp[cur][pos][y+i]=min(dp[cur][pos][y+i],dp[pre][x][y]+dis);
    }
    for(i=0;i<=dis&&y-i>=2;i++)
    {
        if(y-i>pos)
            dp[cur][pos][y-i]=min(dp[cur][pos][y-i],dp[pre][x][y]+dis);
    }
}
void righthand(int pos,int x,int y)
{
    if(pos==1)
    {
        return ;
    }
    int dis=abs(y-pos)+1;
    int i;
    for(i=0;i<=dis&&x+i<=9;i++)
        if(x+i=1;i++)
        if(x-i


你可能感兴趣的:(acm动态规划)