light oj 1068 - Investigation 数位DP
思路:典型的数位DP!!!
dp[i][j][k]:第i位,对mod取余为j,数字和对mod取余为k。
注意:由于32位数字和小于95,所以当k>=95时,结果肯定为0.
这样数组就可以开小点,不会超内存!!
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int dp[][][],bit[],k;
int dfs(int pos,int m,int s,bool f)
{
if(pos==-) return !m&&!s;
if(!f&&dp[pos][m][s]!=-) return dp[pos][m][s];
int ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
ans+=dfs(pos-,(*m+i)%k,(s+i)%k,f&&i==e);
}
if(!f) dp[pos][m][s]=ans;
return ans;
}
int cal(int n)
{
int m=;
while(n){
bit[m++]=n%;
n/=;
}
return dfs(m-,,,);
}
int main()
{
int t,ca=,a,b,ans;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&a,&b,&k);
memset(dp,-,sizeof(dp));
if(k>=) ans=;
else ans=cal(b)-cal(a-);
printf("Case %d: %d\n",++ca,ans);
}
return ;
}
light oj 1068 - Investigation 数位DP的更多相关文章
- LightOJ 1068 Investigation (数位dp)
problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...
- lightoj 1068 - Investigation(数位dp)
An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is d ...
- Light OJ 1068
数位DP #include <cstdio> #include <cstring> using namespace std; ; ; long long n; int f[MA ...
- [Swust OJ 1097]--2014(数位dp)
题目链接:http://acm.swust.edu.cn/problem/1097/ Time limit(ms): 1000 Memory limit(kb): 32768 今年是2014年,所 ...
- light oj 1068 数位dp
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...
- Light OJ 1031---Easy Game(区间DP)
题目链接 http://lightoj.com/volume_showproblem.php?problem=1031 Description You are playing a two player ...
- (light OJ 1005) Rooks dp
http://www.lightoj.com/volume_showproblem.php?problem=1005 PDF (English) Statistics Forum Tim ...
- Light OJ 1013 Love Calculator(DP)
题目大意: 给你两个字符串A,B 要求一个最短的字符串C,使得A,B同时为C的子串. 问C最短长度是多少? C有多少种? 题目分析: 做这道题目的时候自己并没有推出来,看了网上的题解. 1.dp[C串 ...
- Light OJ 1005 - Rooks(DP)
题目大意: 给你一个N和K要求确定有多少种放法,使得没有两个车在一条线上. N*N的矩阵, 有K个棋子. 题目分析: 我是用DP来写的,关于子结构的考虑是这样的. 假设第n*n的矩阵放k个棋子那么,这 ...
随机推荐
- outlook配置
有时打开outlook报错.步骤如下: 一.打开控制面板-邮件-电子邮件账户-新建 二.具体设置如下: 三.点第二步上的“其他设置(M)”.做发送服务器.
- C# 获取图片的EXIF 信息
关于 EXIF 信息的介绍. 1 EXIF,是英文Exchangeable Image File(可交换图像文件)的缩写.EXIF是一种图像文件格式,只是文件的后缀名为jpg.EXIF信息是由数码相 ...
- cocos中使用VS自动创建工程的方法
为了省事,直接用VS编写了一小段代码,将cocos手动创建工程的命令改用system来执行,免去了手动输入命令的麻烦 其中: -d F:\\cocos2d-x-3.2-projects 是你要存放的工 ...
- java 判断两个数是否异号
java 整型int占4个字节32位,两个数异或后移动31位判断结果,如果是1则异号,如果是0则同号 public class ShowEnviromentViarible { public stat ...
- Android -- Layout布局文件里的android:layout_height等属性为什么会不起作用?
有的时候,我们配置好的布局文件,在加载完成添加到我们的Activity中后发现,并没有安装我们设置的属性来布局,比如我们设置了android:layout_marginTop="100dip ...
- 【转】linux root用户ifconfig报command not found
解决办法: 方法一: 直接输入su - 回车.就可以ifconfig了 方法二: /etc/profile 把下面if语句注释掉: #path Manipulation if ["EUID& ...
- postmortem report of period M1
一.设想和目标 1.我们的软件主要要解决学长设计的学霸系统中视频及文档的浏览功能问题. 2.时间相对充裕.不过对于我们这些零基础的人来说还是比较困难. 3.我们团队中不同意见通常会进行进一步讨论,说出 ...
- 学习JQuery的$.Ready()与OnLoad事件比较
$(document).Ready()方法 VS OnLoad事件 VS $(window).load()方法接触JQuery一般最先学到的是何时启动事件.在曾经很长一段时间里,在页面载入后引发的事件 ...
- 【CentOS】设置静态IP
问题描述: CentOS配置静态IP 问题解决: (1)修改IP--修改配置文件/etc/sysconfig/network-scripts/ifcfg-eth ...
- Asp.net 导入Excel(服务器不带Office)
#region 把excel文件转换为DataSet. /// <summary> /// 把excel文件转换为DataSet. /// </summary> /// < ...