HDU(3555),数位DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 15372 Accepted Submission(s): 5563
counter-terrorists found a time bomb in the dust. But this time the
terrorists improve on the time bomb. The number sequence of the time
bomb counts from 1 to N. If the current number sequence includes the
sub-sequence "49", the power of the blast would add one point.
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
first line of input consists of an integer T (1 <= T <= 10000),
indicating the number of test cases. For each test case, there will be
an integer N (1 <= N <= 2^63-1) as the description.
The input terminates by end of file marker.
1
50
500
1
15
From 1 to 500, the numbers that include the sub-sequence "49" are "49","149","249","349","449","490","491","492","493","494","495","496","497","498","499",
so the answer is 15.
#include <stdio.h>
#include <string.h> int bit[];
long long dp[][]; long long dfs(int len,bool is4,bool ismax)
{
if(len==) return ; ///搜索成功
if(!ismax&&dp[len][is4]>=) return dp[len][is4]; long long cnt = ;
int maxnum = ismax? bit[len]:;
for(int i=; i<=maxnum; i++)
{
if((is4&&i==)) continue;
cnt +=dfs(len-,i==,ismax&&i==maxnum);
}
return ismax?cnt:dp[len][is4]=cnt;
} long long f(long long n)
{
int len = ;
while(n)
{
bit[++len] = n%;
n/=;
}
return dfs(len,false,true);
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long n;
scanf("%lld",&n);
memset(dp,-,sizeof(dp));
printf("%lld\n",n-f(n)+);
}
return ;
}
HDU(3555),数位DP的更多相关文章
- HDU 3555 数位dp入门
开始想用dp[i][j]来记录第i位j开头含有49的数的个数 但是init后并不知道如何进行cal 想了想可以用不要62的思想 当作不要49来做 然后减一下 就好 看网上的代码 不要62和这道题用的d ...
- HDU 3555 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- hdu 3555数位dp基础入门题
#include<stdio.h> #define N 20 long long dp[N][3]; void init(){ long long i; dp[0][0]=1; for ...
- Bomb HDU - 3555 数位dp
Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...
- hdu:2089 ( 数位dp入门+模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...
- HDU 4352 XHXJ's LIS HDU(数位DP)
HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下 ...
- hdu 3709 数位dp
数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...
随机推荐
- Lintcode: Subarray Sum Closest
Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first nu ...
- 树形DP +01背包(HDU 1011)
题意:有n个房间,有n-1条道路连接着n个房间,每个房间都有若干个野怪和一定的能量值,有m个士兵从1房间入口进去,到达每个房间必须要留下若干士兵杀死所有的野怪,然后其他人继续走,(一个士兵可以杀死20 ...
- UML: 状态机图
摘自http://www.umlonline.org/school/viewthread.php?tid=39 活动图将流程分解为一个一个的活动,通过活动的先后顺序来展示流程:而状态机图从某个物品的状 ...
- return 的用法 初探
#include<stdio.h> int imin(int ,int ); int main() { int evil1,evil2; ) //注意 第二个%d后面不能有空格,大概这就是 ...
- /Users/alamps/AndroidStudioProjects/Demo11ListView
package com.example.demo11listview; import android.os.Bundle; import android.app.Activity; import an ...
- oracle的系统文件的查询
1:查看实例和数据库的相关信息 --查看实例 select instance_name,version,status,archiver,database_status from v$instance; ...
- url传参
1.两种url形式传参index.php/action/function/id/2 这种模式下:$_GET[action]就是function,$_GET[id]就是2
- React快速入门
目录: 简介 Hello React! 虚拟DOM React组件 轮子来了:JSX 使用JSX 简介 React是Facebook开源的一个用于构建用户界面的Javascript库,已经 应用于Fa ...
- ReportingService 通过RowNumber函数获取行号和生成隔行变色样式
以前一直没有搞明白SSRS里面的RowNumber函数到底该怎么用,所以一直没有很好的办法在SSRS中的表格上实现隔行变色的样式,实现隔行变色的关键就是获取表格中每一行的行号.在最近了解了下这个函数, ...
- Angularjs之基本概念梳理(一)
1.Angularjs指令属性ng-app和ng-controller的理解 ng-app指令-标记了AngularJS脚本的作用域,在<html>中添加ng-app属性即说明整个< ...