首页 > 代码库 > [HDOJ3555]Bomb(数位DP)
[HDOJ3555]Bomb(数位DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555
同理不要62,这回是要求带49的数,那么先求出不带49的,再减去。
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define fr first 4 #define sc second 5 #define cl clear 6 #define BUG puts("here!!!") 7 #define W(a) while(a--) 8 #define pb(a) push_back(a) 9 #define Rint(a) scanf("%d", &a)10 #define Rll(a) scanf("%I64d", &a)11 #define Rs(a) scanf("%s", a)12 #define Cin(a) cin >> a13 #define FRead() freopen("in", "r", stdin)14 #define FWrite() freopen("out", "w", stdout)15 #define Rep(i, len) for(int i = 0; i < (len); i++)16 #define For(i, a, len) for(int i = (a); i < (len); i++)17 #define Cls(a) memset((a), 0, sizeof(a))18 #define Clr(a, x) memset((a), (x), sizeof(a))19 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))20 #define lrt rt << 121 #define rrt rt << 1 | 122 #define pi 3.1415926535923 #define RT return24 #define lowbit(x) x & (-x)25 #define onecnt(x) __builtin_popcount(x)26 typedef long long LL;27 typedef long double LD;28 typedef unsigned long long ULL;29 typedef pair<int, int> pii;30 typedef pair<string, int> psi;31 typedef pair<LL, LL> pll;32 typedef map<string, int> msi;33 typedef vector<int> vi;34 typedef vector<LL> vl;35 typedef vector<vl> vvl;36 typedef vector<bool> vb;37 38 const int maxn = 25;39 40 LL digit[maxn];41 LL dp[maxn][2];42 43 LL dfs(int l, bool num, bool jud) {44 if(l == 0) return dp[l][num] = 1;45 if(!jud && ~dp[l][num]) return dp[l][num];46 LL ret = 0;47 int nex = jud ? digit[l] : 9;48 Rep(i, nex+1) {49 if(num && i == 9) continue;50 ret += dfs(l-1, i==4, jud&&i==nex);51 }52 if(!jud) dp[l][num] = ret;53 return ret;54 }55 56 LL f(LL num) {57 int pos = 0;58 while(num) {59 digit[++pos] = num % 10;60 num /= 10;61 }62 return dfs(pos, false, true);63 }64 65 LL n;66 67 signed main() {68 //FRead();69 Clr(dp, -1);70 int T;71 Rint(T);72 W(T) {73 cin >> n;74 cout << n - f(n) + 1 << endl;75 }76 RT 0;77 }
[HDOJ3555]Bomb(数位DP)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。