HDU Word Index (数位DP)

题意:给你字符串,算出它的数值;

a -> 1

b -> 2

.

.

z -> 26

ab -> 27

ac -> 28

.

.

az -> 51

bc -> 52

.

.

vwxyz -> 83681

字母要求递增。

#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include <queue>
#include <stack>
#include<algorithm>
#include<set>
using namespace std;
#define INF 1e8
#define eps 1e-4
#define ll __int64
#define maxn 100005
#define mol 112233 

char s[10];
int dp[10][40],l;

// pos:位数,st:当前字母,p:是否有限制,flag:回溯到目标位置
int dfs(int pos,int st,int p,int flag)
{
	if(pos==l)
		return 1;
	int u=flag?s[pos]-‘a‘+1:26;
	int ans=0;
	if(!p)
		for(int i=st+1;i<=u;i++)
			ans+=dfs(pos+1,i,0,flag&&u==i);
	else
		for(int i=0;i<=u;i++)
			ans+=dfs(pos+1,i,i==0,flag&&u==i);
	if(!flag)
		return dp[pos][st]=ans;
	return ans;
}
int main()
{
	while(~scanf("%s",s))
	{
		int i,j=0;
		l=strlen(s);
		for(i=1;i<l;i++)
			if(s[i]-s[i-1]<=0){
				j=1;break;
			}
		if(j)
		{
			printf("0\n");
			continue;
		}
		else
			printf("%d\n",dfs(0,0,1,1)-1);

	}
	return 0;
}

HDU Word Index (数位DP)

时间: 2024-08-25 14:01:02

HDU Word Index (数位DP)的相关文章

uva 417 - Word Index(数位dp)

题目连接:uva 417 - Word Index 题目大意:按照题目中的要求,为字符串编号,现在给出字符串,问说编号为多少,注意字符串必须为递增的,否则编号为0. 解题思路:其实就是算说比给定字符串小并且满足递增的串由多少个.dp[i][j]表示第i个位为j满足比给定字符串小并且满足递增的串. dp[i][j]=∑k=0j?1dp[i?1][k]. 注意每次要处理边界的情况,并且最后要加上自身串.并且在处理边界的时候dp[i][0]要被赋值为1,代表前i个为空的情况. #include <cs

[ACM] hdu 3555 Bomb (数位DP,统计1-N中含有“49”的总数)

Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7187 Accepted Submission(s): 2512 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro

HDU——B-number(数位DP)

题目大意: 要找出1到n之间有多少个数含13,并且能被13整除 记忆化搜索: dp[pos][pre][mod][statu],pos位数,pre前一位,mod余数,statu状态 有2个状态:含13,不含13 <span style="font-size:18px;"><strong>#include<iostream> #include<cstring> #include<cstdio> #include<algor

HDU 3555 Bomb (数位DP)

数位dp,主要用来解决统计满足某类特殊关系或有某些特点的区间内的数的个数,它是按位来进行计数统计的,可以保存子状态,速度较快.数位dp做多了后,套路基本上都差不多,关键把要保存的状态给抽象出来,保存下来. 简介: 顾名思义,所谓的数位DP就是按照数字的个,十,百,千--位数进行的DP.数位DP的题目有着非常明显的性质: 询问[l,r]的区间内,有多少的数字满足某个性质 做法根据前缀和的思想,求出[0,l-1]和[0,r]中满足性质的数的个数,然后相减即可. 算法核心: 关于数位DP,貌似写法还是

HDU 5898 (数位DP)

HDU 5898 odd-even number 题意:如果一个数连续的奇数之和为偶数,连续的偶数之和为奇数则满足条件,问某一区间内满足条件的数字的个数. 思路:数位DP,dp[i][j][k][u]表示计算到底i位,是否为临界值,上一位是奇还是偶,连续奇或偶有u个,在dfs是多记录一下该数前面是不是全为0以及该数是不是已近不满足条件. #include<cstdio> #include<cstring> #include<iostream> #include<a

HDU 2089 简单数位dp

1.HDU 2089  不要62    简单数位dp 2.总结:看了题解才敲出来的,还是好弱.. #include<iostream> #include<cstring> #include<cstdio> using namespace std; int dp[10][11]; //dp[i][j]表示以j为首位符合条件的i位数的个数 void init() //预处理 { memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=1

HDU(3555),数位DP

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 15372    Accepted Submission(s): 5563 Problem Description The counter-terrorists f

hdu 3555(数位dp 入门)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7716    Accepted Submission(s): 2702 Problem Description The counter-terrorists found a

HDU 3555 Bomb(数位DP)

Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets