USACO2014Open Silver 奶牛的叫唤2.0

Problem 3: Odometer [Brian Dean, 2014]

Farmer John’s cows are on a road trip! The odometer on their car
displays an integer mileage value, starting at X (100 <= X <= 10^18)
miles at the beginning of their trip and ending at Y (X <= Y <= 10^18)
miles at the end of their trip. Whenever the odometer displays an
‘interesting’ number (including at the start and end of the trip) the
cows will moo. A number is ‘interesting’ if when you look at all its
digits except for leading zeros, at least half of these should be the
same. For example, the numbers 3223 and 110 are interesting, while
the numbers 97791 and 123 are not.

Help FJ count how many times the cows will moo during the trip.

一道位数dp题(题目不难坑却很多);

找从x~y实在是很麻烦,但是找从1~x,和从1~y的数明显方便(而且复杂度也肯定不会上升)
所以,主要思路就是得到 1~(x-1) 和 1~y 的有趣数,然后减一下就好了;

先枚举以哪个数为有趣数,
每次从0~9里选一个放在末尾,并保证不会超过x,放到和x的位数相同,然后看一下是不是有趣数就好了
这个dp还是很好写的.

但是,这样还没有结束,既然是 1~x 为什么不可以在前面放好几个 0 呢,
所以,还要对前导零特判.

最后,还会发现会出现重复,
像形如 1122 的,在 1和2 都会被算到一遍,
也就是还需要一遍dp把这些毒瘤去掉.
(这个dp和前面的差不多)

#include <iostream>
#include <cstring>
using namespace std;
const int M=25;
const int base=20;
typedef long long longl;

longl dp[M][2][2][M*2];
longl rdp[M][2][
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值