ABC154 E - Almost Everywhere Zero
数位DP模板,记忆化+限制即可
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; int n, K, dp[][][];
char str[]; int dfs(int m, int use, int limit) {
if(use > K) return ;
if(m > n) return use == K;
if(dp[use][m][limit] != -) return dp[use][m][limit];
int up = limit == ? str[m]-'':, ans = ;
for(int i = ; i <= up; ++i)
ans += dfs(m+, use+(i!=), limit&&i==up);
return dp[use][m][limit] = ans;
} void run_case() {
cin >> (str+) >> K;
n = strlen(str+);
memset(dp, -, sizeof(dp));
cout << dfs(, , );
} int main() {
ios::sync_with_stdio(false), cin.tie();
//cout.setf(ios_base::showpoint);cout.precision(8);
run_case();
cout.flush();
return ;
}
ABC154 E - Almost Everywhere Zero的更多相关文章
随机推荐
- Codeforce 977E Cyclic Components
dfs判断图的连通块数量~ #include<cstdio> #include<algorithm> #include<vector> #include<cs ...
- 实现简单ORM案例
ORM框架: • 我们希望设计一个可以实现对象和SQL自动映射的框架,但是整体用法和设计比Hibernate简单.砍掉不必要的功能.• 会穿插使用设计模式• 增加 – 将对象对应成sql语句,执行sq ...
- 小程序云函数调用http或https请求外部数据
参考网址 https://blog.csdn.net/qiushi_1990/article/details/101220920 小程序云函数调用http或https请求外部数据 原创编程小石头 发布 ...
- linux kali 的ifconfig命令
ifconfig命令 1.ifconfig执行页面 root@localhost:/home/zys# ifconfig lo: flags=73<UP,LOOPBACK,RUNNING> ...
- 输入流输出流IO的理解
之前对IO理解总是有点模糊, 输入输出,其实针对 数据处理主体 A ,这个主体我们通常是指服务器程序本身, 交互目的源B ,一般是本地磁盘,由本地磁盘IO传输, 或者 远程客户端,由网络IO传输. ...
- sort、uniq 、 join 、 comm、diff 、 patch 、df、du 和 time 命令的用法
1 sort 命令 同文本文件打交道时,总避不开排序,那是因为对于文本处理任务而言,排序(sort)可以起到不小的作用.sort 命令能够帮助我们对文本文件和 stdin 进行排序操作.通常,它会结合 ...
- 微信小程序加密解密 C# 以及 填充无效,无法被移除错误的解决方案 Padding is invalid and cannot be removed
解密加密源码 using System; using System.Security.Cryptography; using System.Text; namespace Wechat { publi ...
- SSH框架整合,启动Tomcat报错:Unable to load configuration
报错信息: 严重: Dispatcher initialization failed Unable to load configuration. - bean - file:/E:/MIKEY/mik ...
- python基础之省份三级菜单
菜单 menu = { #定义一个字典 '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, '汽车之家 ...
- JS闭包(3)
在将内部函数作为函数的返回值的时候,由于闭包的存在会携带上内部函数所使用的外部函数的变量,如果这些变量很多或者很大,那么在使用完返回的内部函数后最好将其置为null以便释放闭包中的携带变量,一面造成内 ...