hdu4389 X mod f(x)
这个题因为总和加起来是比较小的9*9 = 81 这样可以保留前面枚举的数对所有的可能出现的和的余数,然后依次向下找。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int dp[][][][];
int d[];
int dfs(int i,int e,int sum,int m,int r)
{
if(i==-)
{
return r==&&(sum==m);
}
if(!e&&dp[i][sum][m][r]!=-) return dp[i][sum][m][r];
int mk = e?d[i]:;
int ans = ;
for(int j = ; j <= mk ; j++)
{
ans+=dfs(i-,e&&j==mk,sum+j,m,(r*+j)%m);
}
return e?ans:dp[i][sum][m][r] = ans;
}
int cal(int x)
{
int g = ;
if(x<=) return ;
while(x)
{
d[g++] = x%;
x/=;
}
int ans = ;
for(int i = ; i <= ; i++)
{ int k = dfs(g-,,,i,);
ans+=k;
}
return ans;
}
int main()
{
int t,a,b;
cin>>t;
int kk = ;
memset(dp,-,sizeof(dp));
while(t--)
{
cin>>a>>b;
printf("Case %d: ",++kk);
cout<<cal(b)-cal(a-)<<endl;
}
return ;
}
hdu4389 X mod f(x)的更多相关文章
- HDU4389:X mod f(x)(数位DP)
Problem Description Here is a function f(x): int f ( int x ) { if ( x == 0 ) return 0; return f ( x ...
- HDOJ 4389 X mod f(x)
数位DP........ X mod f(x) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 4389——X mod f(x)(数位DP)
X mod f(x) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- HDU X mod f(x)(题解注释)
X mod f(x) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU - 4389 X mod f(x)(数位dp)
http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 为[A,B] 区间内的数能刚好被其位数和整除的数有多少个. 分析 典型的数位dp...比赛时想不出状 ...
- hdu 4389 X mod f(x) 数位DP
思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...
- HDU 4389 X mod f(x)
题意:求[A,B]内有多少个数,满足x % f(x) == 0. 解法:数位DP.转化为ans = solve(b) - solve(a - 1).设dp[i][sum][mod][r]表示长度为i, ...
- 数位dp总结
由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...
- Codeforces F. Cowmpany Cowmpensation
Description 有一棵树,现在要给每个节点赋一个在1到D之间的权值,问有多少种方案满足任意一个节点的权值都不大于其父亲的权值. n<=3000,D<=1e9 题面 Solution ...
随机推荐
- Markdown语法速查
Markdown教程:http://wowubuntu.com/markdown/ h1 # h1 h2 ## h2 h3 ### h3 h4 #### h4 h5 ##### h5 h6 ##### ...
- 换手率的公司使用MQTT的框架
向换手率公司学习.该公司貌似也使用 Golang
- C# xml压缩包不解压的情况下解析xml内容
string sourceFilePath = @"E:\文件拷贝\xx\3773\3773.zip"; FileInfo fileInfo = new FileInfo(sour ...
- linux下用户账户切换
1,)当前我已经登录一个用户hadoop,我怎么切换到root账户呢(应为一般用户经常会遇到无权限修改/etc/hosts./ect/hostname等文件的权限)? 使用命令sudo su root ...
- Lua自己实现string.split功能
local function split(str, d) --str是需要查分的对象 d是分界符 local lst = { } local n = string.len(str)--长度 local ...
- Design and Analysis of Algorithms_Introduction
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...
- Access数据库中Sum函数返回空值(Null)时如何设置为0
在完成一个Access表中数据统计时,需要统计指定字段的和,使用到了Sum函数,但统计时发现,指定条件查询统计时有可能返回空值(Null),导致对应字段显示为空白,正常应显示为0.基本思路是在获取记录 ...
- mfc ui3
引用:http://www.cnblogs.com/rainbowzc/archive/2010/06/02/1749872.html 本文专题讨论VC中的界面美化,适用于具有中等VC水平的读者.读者 ...
- 内存缓存机制and垃圾回收机制
一.内存缓存机制 var_dump(memory_get_usage(true)); $a="laruence"; var_dump(memory_get_usage(true)) ...
- Magento 自定义一个搜索功能
最近工作中有一个需求是需要做一个搜索的功能,但是因为需要定制一些外观,所以就不用传统的方法来继承基类GRID.实现这个需求的核心其实就是下面这个方法. $this->getLayout()-&g ...