您的位置:首页 > 其它

poj 2033 Alphacode

2015-07-06 18:23 323 查看
确定第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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: