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的更多相关文章
随机推荐
- QAction菜单行为
/*File*/ QAction* close_action_; /*File*/ QAction* close_action_;
- webpack使用devtool :source map插件
链接 : https://www.cnblogs.com/chris-oil/p/8856020.html
- jQuery学习(三)
jQuery文档操作方法 1.内部追加内容 选择器追加到内容 append(content)在当前jQuery对象内部所包含的DOM对象的内部的最后追加content对应的内容,其中content可以 ...
- 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...
- 动态规划-爬楼梯问题java实现
最近开始看算法导论,研究了一下动态规划,下面就开始直入主题开始记录近期看的第一个知识点动态规划.提起动态规划就不得不提几个动态规划的金典问题爬楼梯.国王金矿.背包问题.今天就仔细分析一下爬楼梯问题. ...
- pytorch资料
torchvision是独立于pytorch的关于图像操作的一些方便工具库. torchvision的详细介绍在:https://pypi.org/project/torchvision/ torch ...
- 监控Tomcat状态!(重点)
方法一:开发JAVA监控页面 [root@localhost ~]# mkdir /usr/local/tomcat8/webapps/memtest/[root@localhost ~]# cd / ...
- BIND DNS配置!
1.RPM 包的主要作用bind:提供了域名服务器的主要程序及相关文件bind-utils:提供了对 DNS 服务器的测试工具程序,如 nslookup 等bind-libs:提供了 bind.bin ...
- connection String加密
aspnet_regiis -pe "connectionStrings" -app "/HG" -prov "ChrisProvider" ...
- WEB安全 - XSS,CSRF
1. CSRF参考 https://www.ibm.com/developerworks/cn/web/1102_niugang_csrf/ https://en.wikipedia.org/wiki ...