【POJ 1850】 Code
来源:互联网 发布:ubuntu镜像源 编辑:程序博客网 时间:2024/06/10 08:57
【POJ 1850】 Code
还是很想说
数位dp真的很方便!!!
数位dp真的很方便!!!
数位dp真的很方便!!!
重要的事说三遍
该题转换规则跟进制差不多 到z时进一位 如az下位为bc 上位必须比下位小
根据这个规则搜出所有情况即可
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int dp[11][27];int digit[11];/*1~26表示加的字母 0表示不加有前导时 枚举pre+1 ~ 26-pos没有的话枚举 0 ~ 26-pos*/int dfs(int pos,int pre,bool high){ if(pos == -1) return pre > 0; if(!high && ~dp[pos][pre]) return dp[pos][pre]; int i,en,ans = 0,st; en = high? digit[pos]: 26-pos; st = pre? pre+1: 0; for(i = st; i <= en; ++i) ans += dfs(pos-1,i,high && i == en); if(!high) dp[pos][pre] = ans; return ans;}int Solve(char *str){ int i,len = strlen(str); for(i = 0; i < len; ++i) { digit[i] = str[len-i-1]-'a'+1; } return dfs(len-1,-1,1);}int main(){ memset(dp,-1,sizeof(dp)); char str[11],i; scanf("%s",str); for(i = 0; str[i+1]; ++i) { if(str[i] >= str[i+1]) { puts("0"); return 0; } } printf("%d\n",Solve(str)); return 0;}
0 0
- poj 1850 Code
- poj 1850 Code
- poj 1850 code
- poj 1850 Code
- poj 1850 Code
- poj 1850 Code
- poj 1850 Code
- POJ 1850 Code
- POJ 1850 Code
- poj 1850 Code
- POJ 1850 Code
- poj 1850 Code
- POJ 1850 Code
- POJ 1850 Code
- POJ 1850--Code
- POJ 1850 Code
- POJ - 1850 Code
- POJ 1850 Code
- 配置文件
- HDU 3746 Cyclic Nacklace(KMP最小循环子串)
- Hibernate中Criteria的完整用法
- fl2440 3G拨号
- iOS 开发的一些小技巧篇
- 【POJ 1850】 Code
- Centos 内存占满 释放内存
- 软件工程常用技术
- jsp and servlet
- 三种基本布局(不常用)以及全屏和Activity的两种启动方式
- Java IO最详解
- PullToRefreshGridView改变下拉的文字(2015.8.19第一次使用csdn博客)
- 参考大神的职业规划路线(变相技能树)
- eclipse 与 android studio 一些常用的对应快捷键