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. 创建一个叫做People的类: 属性:姓名、年龄、性别、身高 行为:说话、计算加法、改名 编写能为所有属性赋值的构造方法; (2)创建主类: 创建一个对象:名叫“张三”,性别“男”,年龄18岁,身高1.80; 让该对象调用成员方法: 说出“你好!” 计算23+45的值 将名字改为“李四”

    package com.chuoji; public class People { private String name; private int age; private String sex; ...

  2. ajax 代码

    function ajax(){ var aj=null; if(window.ActiveXObject){ aj = new ActiveXObject("Microsoft.XMLHT ...

  3. fork &vfork --陈皓

    http://coolshell.cn/articles/7965.html http://coolshell.cn/articles/12103.html#more-12103 前两天有人问了个关于 ...

  4. Doctrine2 SQL语句

    $q = Doctrine_Query::create() ->update('WebusersTable q') ->set('q.login_name','?','John') ) - ...

  5. Android first---放置在外存中的文件读取

    照样以登录案例举例: 第一步:界面绘制:跟之前写过的一个案例一样 第二步:逻辑代码 public class MainActivity extends Activity { //定义全局变量    p ...

  6. Android 获取全部应用

      package com.lvshandian.menshen.download;import android.content.Context;import android.content.Inte ...

  7. Linux -- 文件统计常用命令

    标签(空格分隔): Linux sort -- 文件内排序命令 sort将文件的每一行作为一个单位,相互比较,比较原则是从首字符向后,依次比较其ASCII码. 按每行升序排序: sort seq.tx ...

  8. Django ModelForm and Form

    django表单系统中,所有的表单类都作为django.forms.Form的子类创建,包括ModelForm 关于django的表单系统,主要分两种 基于django.forms.Form 基于dj ...

  9. redis windows下使用及redis命令

    出自:http://www.cnblogs.com/chenping-987123/archive/2012/01/29/2331079.html Redis 是一个开源,高级的键值对的存储.它经常作 ...

  10. Spring 数据库配置用户名和密码加密

    单个数据库配置 : 一般spring容器启动时,通过PropertyPlaceholderConfigurer类读取jdbc.properties文件里的数据库配置信息.通过这个原理,我们把加密后的数 ...