onmywaying

不困于情,不畏于心

poj 2033 Alphacode

确定第i+2 个元素与第i个元素和第i+1的元素的关系即可

/*
#include<iostream>
#include<string.h>
#include<math.h>
#include<fstream>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector> 
#define MAXSIZE 100
using namespace std;
typedef long long int ll;
ll a = 0;
int dat[100000010]; 
int dp[10000010];
int ind = 0;
void getEverynum()
{
    while(a)
    {
        int t = a % 10;
        dat[ind++] = t;
        a = a / 10;
    } 
}
int main()
{
    freopen("data_2033.txt","r",stdin);
    while(true)
    {
        ind = 1;
        memset(dat, 0, sizeof(dat));
        memset(dp, 0, sizeof(dp));
        scanf("%d", &a);
        if (a == 0)
        {
            break;
        }
        getEverynum();
        //dp[1] = 1;
        for (int i = 1; i < ind; i++)
        {
            if (dat[i + 1] < '7')
            {
                dp[i + 1] = dp[i] + 2;
                i += 1;
            }else
            {
                dp[i + 1] = max (dp[i] + 1, dp[i - 1] + 2);
            }
        }
        printf("%d\n", dp[ind]);
    }

    return 0;
}*/

#include<iostream>
#include<string.h>
#include<math.h>
#include<fstream>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector> 
#define MAXSIZE 100
using namespace std;

int dp[100010];
int main()
{
    //freopen("data_2033.txt","r",stdin);
    char s[100010];
    while(true)
    {
        scanf("%s", s);
        if (s[0] == '0')
        {
            break;
        }
        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= strlen(s); i++)
        {
            dp[i] = 0;
            if (s[i - 1] != 48)
            {
                dp[i] += dp[i - 1];
            }
            if (s[i - 1] - 48 + s[i - 2] * 10 - 480 <= 26 && s[i - 2] != 48)
            {
                dp[i] += dp[i - 2];
            }
        }
        printf("%d\n", dp[strlen(s)]);
    }

    return 0;
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013486906/article/details/46777691
个人分类: 动态规划
上一篇poj 2029 Get Many Persimmon Trees
下一篇poj 2063 Investment
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭