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. [Linux] VIM 常用快捷键2

    如何使用MacVim 1.在插入模式之外 基本上来说,你应该尽可能少的呆在插入模式里面,因为在插入模式里面 VIM 就像一个“哑巴”编辑器一样.很多新手都会一直呆在插入模式里面,因为这样易于使用.但 ...

  2. laravel框架总结(四) -- 服务容器

    1.依赖 我们定义两个类:class Supperman 和 class Power,现在我们要使用Supperman ,而Supperman 依赖了Power class Supperman { p ...

  3. dojox.grid.DataGrid

    创建表格 <table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid" style=&q ...

  4. 我的android学习经历38

    anddroid studio的内存修改 昨天有位朋友问到了下面的一个问题 这个判断为android studio的分配的内存不够用. 据我的了解造成这个的原因主要有以下几个方面: 1.电脑的内存本来 ...

  5. 编写一个JSP程序实现用户登录

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  6. Codeforces Round #339 (Div.2)

    A. Link/Cut Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. 特征的SID表、M表、P表、Q表、X表、Y表、T表

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  8. 封装对MongoDB数据库的增删改查访问方法(基于MongoDB官方发布的C#驱动)

    本文利用MongoDB官方发布的C#驱动,封装了对MongoDB数据库的增删改查访问方法.先用官方提供的mongo-csharp-driver ,当前版本为1.7.0.4714 编写数据库访问帮助类 ...

  9. pycharm 注册

    pycharm在线注册:设置激活服务器 Help->Register->License server 在License server address中填写:http://idea.lany ...

  10. Android handler 详解(面试百分之100问到)

    handler在Android中被称为“消息处理者”,在多线程中比较常用. handler内部实现原理 handler实现机制:1,Message对象,表示要传递的一个消息,内部使用链表数据结构实现一 ...