USACO2014Open Silver 奶牛的叫唤2.0

这道题目涉及奶牛在公路旅行中遇到的有趣里程数问题。有趣数是指去掉前导零后,至少有一半的数字相同。问题转化为计算1到x和1到y之间的有趣数数量。通过位数动态规划方法解决,首先枚举基准有趣数,接着考虑添加0的影响,同时处理重复计算的数字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值