Code

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 11   Accepted Submission(s) : 10
Problem Description
Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that the words are made only of small characters of the English alphabet a,b,c, ..., z (26 characters). From all these words we consider only those whose letters are in lexigraphical order (each character is smaller than the next character).

The coding system works like this: 
The words are arranged in the increasing order of their length. 
The words with the same length are arranged in lexicographical order (the order from the dictionary). 
We codify these words by their numbering, starting with a, as follows: 
a - 1 
b - 2 
... 
z - 26 
ab - 27 
... 
az - 51 
bc - 52 
... 
vwxyz - 83681 
...

Specify for a given word if it can be codified according to this coding system. For the affirmative case specify its code.

 
Input
The only line contains a word. There are some constraints: 
The word is maximum 10 letters length 
The English alphabet has 26 characters. 
 
Output
The output will contain the code of the given word, or 0 if the word can not be codified.
 
Sample Input
bf
 
Sample Output
55
 
Source
PKU

很久没写数位dp了,写这道题还要看着模板写。。。

用记忆化搜索写,套模板很好写

 #include <iostream>
#include <stdio.h>
#include <string>
#include <cstring> using namespace std; int length,digit[],table[][]; //table[i][j]代表长度为i以数字j代表的字母开头的情况
char code[]; int dfs(int len,bool bound,int low,bool zero,int head) //zero代表是否有前导零,low代表循环的下届
{
if(len==)
return zero?:; //排除全是0的情况
if(!zero&&!bound&&table[len][head]!=-)
return table[len][head];
int up=bound?digit[len]:;
int ret=;
for(int i=low;i<=up;i++)
{
ret+=dfs(len-,bound&&i==up,(zero&&i==)?:i+,zero&&i==,i);
}
if(!zero&&!bound)
table[len][head]=ret;
return ret;
} int fun()
{
int i;
for(i=;i<length;i++)
{
digit[length-i]=code[i]-'a'+;
}
return dfs(length,true,,true,);
} int main()
{
memset(table,-,sizeof(table));
scanf("%s",code);
int ans,i;
length=strlen(code);
bool f=true;
for(i=;i<length-;i++) //如果无法产生结果,ans=0
if(code[i]>code[i+])
f=false;
if(!f)
ans=;
else
ans=fun();
printf("%d\n",ans);
return ;
}

三部曲一(搜索、数学)-1016-Code的更多相关文章

  1. HDU 4294 Multiple(搜索+数学)

    题意: 给定一个n,让求一个M,它是n个倍数并且在k进制之下 M的不同的数字最少. 思路: 这里用到一个结论就是任意两个数可以组成任何数的倍数.知道这个之后就可以用搜索来做了.还有一个问题就是最多找n ...

  2. 生日蛋糕 POJ - 1190 搜索 数学

    http://poj.org/problem?id=1190 题解:四个剪枝. #define _CRT_SECURE_NO_WARNINGS #include<cstring> #inc ...

  3. Leetcode初级算法(排序和搜索+数学篇)

    合并两个有序数组 开始的时候将这道题理解错了,发现几个奇怪的测试案例后才明白这道题什么意思.本来的想法就是把nums2全部放到num1里面,然后删除重复元素.排序一下,就有了下面的代码: class ...

  4. Python黑帽编程1.2 基于VS Code构建Python开发环境

    Python黑帽编程1.2  基于VS Code构建Python开发环境 0.1  本系列教程说明 本系列教程,采用的大纲母本为<Understanding Network Hacks Atta ...

  5. bnuoj 33656 J. C.S.I.: P15(图形搜索题)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=33656 [题解]:暴力搜索题 [code]: #include <iostream> # ...

  6. EF 中 Code First 的数据迁移以及创建视图

    写在前面: EF 中 Code First 的数据迁移网上有很多资料,我这份并没什么特别.Code First 创建视图网上也有很多资料,但好像很麻烦,而且亲测好像是无效的方法(可能是我太笨,没搞成功 ...

  7. Code Review Checklist

    左按:当年需要一份详细的代码评审清单作参考,翻译了此文. 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[-] General Code Smoke Test 通用测试 Comm ...

  8. luogu 1731 搜索剪枝好题

    搜索剪枝这个东西真的是骗分利器,然鹅我这方面菜的不行,所以搜索数学dp三方面是真的应该好好训练一下 一本通的确该认真的刷嗯 #include<bits/stdc++.h> using na ...

  9. 图解Windows 10下Visual Studio Code的下载和安装

    1. 百度搜索“Visual Studio Code”,如下图所示: 2. 点击第一个搜索结果项,进入官方网站,然后点击“Download for Windows”,如下图所示: 3. 进入提示下载页 ...

随机推荐

  1. Android 编译时注解解析框架

    2.注解 说道注解,竟然还有各种分类,得,这记不住,我们从注解的作用来反推其分类,帮助大家记忆,然后举例强化大家的记忆,话说注解的作用: 1.标记一些信息,这么说可能太抽象,那么我说,你见过@Over ...

  2. 学DIV+CSS技术,如何入门?(2)

    http://www.zhangbin.in/a/jishuziliao/CSSjishu/2014/0730/13267_2.html

  3. 【noip新手入门向】OpenJudge1.3-14大象喝水

    一.写在前面 我也不知道我为什么要写这个鬼畜的东西←_←才不是为了水blog量什么的(划掉),其实是为了明天给学弟学妹们传教准备. 这道题对完全对c语言没有概念的小萌新们极度友好,可以锻炼小萌新们的代 ...

  4. R----Shiny包介绍学习

    为什么用Shiny Shiny让数据分析师写完分析与可视化代码后,稍微再花几十分钟,就可以把分析代码工程化,将分析成果快速转化为交互式网页分享给别人.所以,如果你是一名使用R的数据分析师,选择Shin ...

  5. 【Unity3D游戏开发】NGUI之多分辨率下完美分布式协同开发 (五)

    NGUI多分辨率下完美分布式协同开发:不同分辨率下相对于屏幕坐标的Perfab数据不再丢失 NGUI多分辨率下完美分布式协同开发不同分辨率下相对于屏幕坐标的Perfab数据不再丢失 开发问题 原因分析 ...

  6. C/C++与Matlab混合编程

    Matlab 拥有丰富的功能,编程简单.不过,有些情况下,Matlab程序的执行速度比较慢.C/C++编译执行的程序速度比较快,编程难度上比Matlab要高一些.因此存在一种方案,就是使用Matlab ...

  7. 笔记本_Lenovo_G480

    ZC: 这是 严g 的笔记本 1.进入 BIOS --> F2键 2.安装 WinServer2003时,蓝屏 2.1.Win2003的PE(不太明白 这里的PE指什么...)不支持 AHCI ...

  8. linux 启动模式

    BLOS-->MBR(master boot record)主引导记录-->引导加载程序-->内核-->init process -->login

  9. SSH2 框架下的分页

    1.设计分页实体(pageBean) 这里我显示的是3-12页的方式: package cn.itcast.oa.domain; import java.util.List; /** * 封装分页信息 ...

  10. 华为WLAN产品介绍-05

    无线AP与AC的区别 WLAN系统一般由AC(接入控制器)和AP(无线接入点)组成. 无线AP,为Access Point简称,一般翻译为“无线访问节点”,它是用于无线网络的无线交换机,也是无线网络的 ...