hdu 2410 Barbara Bennett's Wild Numbers
挺好玩的一道题目。这道题的意思是给出一个模糊值以及一个确定值,要求求出模糊值中大于确定值的个数有多少。
这题我是直接用dfs的方法搜索的,对于每一位如果之前位置的形成的数比确定值当前形成的数小,之后就不可能形成满足要求的值了。如果是大于的,之后的所有问号都可以填入0~9任何一个数字。如果是等于,就要继续搜索下一位。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; typedef long long LL;
char str1[], str2[]; LL dfs(int pos, LL cur1, LL cur2) {
LL ret = ;
if (cur1 < cur2) return ;
if (cur1 > cur2) {
ret = ;
while (str1[pos]) {
if (str1[pos] == '?') ret *= ;
pos++;
}
return ret;
}
if (str1[pos] == || str2[pos] == ) return ;
if (str1[pos] == '?') {
for (int i = ; i <= ; i++) {
if (i < str2[pos] - '') continue;
ret += dfs(pos + , cur1 * + i, cur2 * + str2[pos] - '');
}
} else {
ret += dfs(pos + , cur1 * + str1[pos] - '', cur2 * + str2[pos] - '');
}
return ret;
} int main() {
// freopen("in", "r", stdin);
while (cin >> str1 && str1[] != '#') {
cin >> str2;
cout << dfs(, , ) << endl;
}
return ;
}
——written by Lyon
hdu 2410 Barbara Bennett's Wild Numbers的更多相关文章
- poj 3340 Barbara Bennett's Wild Numbers(数位DP)
Barbara Bennett's Wild Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3153 A ...
- POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)
题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Descript ...
- 【HDU】2138 How many prime numbers
http://acm.hdu.edu.cn/showproblem.php?pid=2138 题意:给n个数判断有几个素数.(每个数<=2^32) #include <cstdio> ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- [DP]数位DP总结
数位DP总结 By Wine93 2013.7 1.学习链接 [数位DP] Step by Step http://blog.csdn.net/dslovemz/article/details/ ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
随机推荐
- linux应用系统日志
在一个典型的LAMP(Linux+Apache+Mysql+Perl)应用环境里: Apache & Nginx; 查找访问和错误日志, 直接找 5xx 错误, 再看看是否有 limit_zo ...
- arcgis增大缩放级别
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- FatMouse' Trade (贪心)
#include <iostream> #include <stdio.h> #include <cstring> #include <cmath> # ...
- qt获取屏幕
m_pDesktopWidget = QApplication::desktop(); // 屏体数量,包含扩展屏 int screenCount = m_pDesktopWidget->scr ...
- 【python小随笔】List列表的常见函数与切片
eval()的使用 n = ["2.3","2.56"] m = [] for i in n: k = eval(i) #只是去了最外层的双引号,单引号, 规定 ...
- PHPCMS快速建站系列之标签循环嵌套
标签循环嵌套方法,可以实现对PC标签循环调用,代码如下: 在此文件里/phpcms/lib/classes/template_cache.class.php 里的 template_parse 方法里 ...
- 「WC2018」即时战略
「WC2018」即时战略 考虑对于一条链:直接随便找点,然后不断问即可. 对于一个二叉树,树高logn,直接随便找点,然后不断问即可. 正解: 先随便找到一个点,问出到1的路径 然后找别的点,考虑问出 ...
- 为什么printf()用%f输出double型,而scanf却用%lf呢?
之前没有注意过这个问题, 转自: http://book.51cto.com/art/200901/106880.htm 问:有人告诉我不能在printf中使用%lf.为什么printf()用%f输 ...
- [React Native] 解析JSON文件
在编写代码时,开发者有时需要存储一些比较多,在应用程序运行时不需要更改的数据.文件大不便于写在代码中,可以把这些数据存储到JSON文件中. 优点非常明显: 1. 数据存放在单独的文件中,代码精简有条理 ...
- 小爬爬6.scrapy回顾和手动请求发送
1.数据结构回顾 #栈def push(self,item) def pop(self) #队列 def enqueue(self,item) def dequeue(self) #列表 def ad ...