数位DP


cxlove基础数位DP第二题

与上题基本相同(其实除了变成long long以外其实更简单了……)

 //HDOJ 3555
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') sign=-; ch=getchar();}
while(isdigit(ch)) {v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=1e7+,INF=~0u>>;
const double eps=1e-;
typedef long long LL;
/*******************template********************/
LL dp[][];
LL len,bit[];
//dp[i][0]表示不含49的i位数字
//dp[i][1]表示不含49,且最高位为9
//dp[i][2]表示存在49
void init(){
dp[][]=;
F(i,,){
dp[i][]=(LL)dp[i-][]*-dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=(LL)dp[i-][]*+dp[i-][];
}
}
LL solve(LL n){
len=; n++;
for(;n;n/=) bit[++len]=n%;
bit[len+]=;
printf("check : ");
D(i,len,) printf("%lld",bit[i]);
printf("\n");
LL ans=;
bool flag=false;
D(i,len,){
ans+=(LL)dp[i-][]*bit[i];
if (flag) ans+=(LL)dp[i-][]*bit[i];
if (!flag && bit[i]>) ans+=dp[i-][];
if (bit[i+]== && bit[i]==) flag=true;
}
return ans;
}
int main(){
init();
int T;LL n;
for(T=getint();T;T--){
scanf("%I64d",&n);
printf("%I64d\n",solve(n));
}
return ;
}

【HDOJ】【3555】Bomb的更多相关文章

  1. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  2. 【集训笔记】博弈论相关知识【HDOJ 1850【HDOJ2147

    以下资料来自:http://blog.csdn.net/Dinosoft/article/details/6795700 http://qianmacao.blog.163.com/blog/stat ...

  3. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  4. 【HDOJ 5379】 Mahjong tree

    [HDOJ 5379] Mahjong tree 往一颗树上标号 要求同一父亲节点的节点们标号连续 同一子树的节点们标号连续 问一共同拥有几种标法 画了一画 发现标号有二叉树的感觉 初始标号1~n 根 ...

  5. HDOJ 1238 Substrings 【最长公共子串】

    HDOJ 1238 Substrings [最长公共子串] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  6. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  7. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  8. 【HDOJ 2089】不要62

    [HDOJ 2089]不要62 第一个数位dp的题 做的老困难了...只是好歹是做出来了 迈出了第一步.. 对大牛来说这样的题都是小case ps:新上一个记忆化方法 一些绕弯的题里用dfs好想些 代 ...

  9. 【HDOJ 5371】 Hotaru&#39;s problem

    [HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...

  10. 【HDOJ 5654】 xiaoxin and his watermelon candy(离线+树状数组)

    pid=5654">[HDOJ 5654] xiaoxin and his watermelon candy(离线+树状数组) xiaoxin and his watermelon c ...

随机推荐

  1. Photoshop CS6的安装

    Photoshop CS6的安装 文件的现在可以从百度软件中下载 安装方法见参考链接,window版的与之类似,亲测成功 参考链接 Mac版Adobe Photoshop CS6 破解过程 Adobe ...

  2. 20150511---Timer计时器(备忘)

    private void timer1_Tick(object sender, EventArgs e) { TimeSpan ts = , , ); string str = ts.Hours + ...

  3. BeanDefinition的Resource定位——2

    1.FileSystemXmlApplicationContext的实现 public class FileSystemXmlApplicationContext extends AbstractXm ...

  4. (转载)浅谈我对DDD领域驱动设计的理解

    原文地址:http://www.cnblogs.com/netfocus/p/5548025.html 从遇到问题开始 当人们要做一个软件系统时,一般总是因为遇到了什么问题,然后希望通过一个软件系统来 ...

  5. JSP_EL使用

    JSP中EL表达式的简单介绍和使用   参考资料: http://www.java3z.com/cwbwebhome/article/article8/8124.html?id=2453   http ...

  6. C# 中有关 using 关键字

    关于 C# 中的 using 关键字 我们往往只在代码的开头使用 using 关键字来引入名称空间,这是 using 的一个最常见的使用. 但是,using 关键字是否只有这么一处用武之地吗? 下面, ...

  7. 【笔记】Windows Phone 8开发笔记之API

    Windows Phone 8 API一览 Windows Phone 7平台不支持Native语言的开发,这困扰了许多游戏和底层应用的开发者.Windows Phone 8 SDK的推出,改善了这个 ...

  8. 【风马一族_Java】在某个范围内,找出具有水仙花特征的数字

    打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如: 153是一个"水仙花数",因为153=1的三 ...

  9. 【Qt】QSettings介绍【转】

    简介 QSettings类提供了持久的跨平台应用程序设置. 用户通常期望应用程序记住它的设置(窗口大小.位置等)所有会话.这些信息通常存储在Windows系统注册表,OS X和iOS的属性列表文件中. ...

  10. $.each遍历json对象

    查看一个简单的jQuery的例子来遍历一个JavaScript数组对象. var json = [ {"id":"1","tagName": ...