zoj3416 Balanced Number
这题纠结了好久,刚开始想到的是正解,不过想到可能会出现一个数支点不唯一的情况,这样就多算了,其实是我想多了,一个数只有一个支点。
这样就好像想到了,枚举支点的位置,保存力矩的状态。
dp[i][k][s] i为当前处理位 k为支点 s为到目前为止根据支点算出来的部分力矩。
有一点需要注意算0的时候 会有len个支点 所以要减掉重算的len-1个
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 2550
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL dp[][][N];
int d[],g;
LL dfs(int i,bool e,int k,int s)
{
if(s<) return ;
if(i==-)
return s==;
if(!e&&~dp[i][k][s])
return dp[i][k][s];
int mk = e?d[i]:;
LL ans = ;
for(int j = ;j <= mk ;j++)
{
//ans+=dfs(i-1,e&&j==mk,s+=j*i,sum+=j);
ans+=dfs(i-,e&&j==mk,k,s+(i-k)*j);
}
// cout<<ans<<" "<<i<<endl;
return e?ans:dp[i][k][s] = ans;
}
LL cal(LL x)
{
if(x<) return ;
if(x==) return ;
g = ;
while(x)
{
d[g++] = x%;
x/=;
}
LL ans = ;
for(int i = ;i < g ; i++)
{
ans+=dfs(g-,,i,);
}
//return dfs(g-1,1,N,0);
return ans-g+;
}
int main()
{
int t;
LL l,r;
cin>>t;
memset(dp,-,sizeof(dp));
while(t--)
{
cin>>l>>r;
cout<<cal(r)-cal(l-)<<endl;
}
return ;
}
zoj3416 Balanced Number的更多相关文章
- HDOJ 3709 Balanced Number
数位DP... Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java ...
- [HDU3709]Balanced Number
[HDU3709]Balanced Number 试题描述 A balanced number is a non-negative integer that can be balanced if a ...
- hdu3709 Balanced Number (数位dp+bfs)
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...
- HDU 3709 Balanced Number (数位DP)
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- HDU3709 Balanced Number (数位dp)
Balanced Number Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- 【HDU 3709】 Balanced Number (数位DP)
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...
- HDU3709:Balanced Number(数位DP+记忆化DFS)
Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is p ...
- hdu 3709 Balanced Number(平衡数)--数位dp
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
随机推荐
- Ffmpeg
Ffmpeg <?php $movefile = "./4.mp4"; $mov = new ffmpeg_movie($movefile); printf("fi ...
- 【后台测试】手把手教你jmeter压测
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5611555.html 我知道我迟早是要踏上了后台测试之路 ...
- C#中判断字符是否大写
在C#中,通常判断一个字符是否为大写字母,有些人可能会第一时间想到用正则表达式,那除了正则表达式,是否还有其他方式呢? 答案是肯定的,先一睹为快,具体代码如下: using System; using ...
- 在项目里交叉使用Swift和OC【转】
Swift and Objective-C in the Same Project在项目里交叉使用Swift和OC Swift与OC的兼容性使得你可以在项目里使用Swift+OC的方式编写应用程序,称 ...
- js 新窗口打开
<script> function tj(){ window.open ('http://www.baidu.com', 'newwindow', 'height=500px, width ...
- JQuery + JSON作为前后台数据交换格式实践
JQuery + JSON作为前后台数据交换 JQuery提供良好的异步加载接口AJAX,可以局部更新页面数据, http://api.jquery.com/category/ajax/ JSON作为 ...
- [Android Tips] 15. Enforcing spaces in string resources
解决方案 使用双引号括起来 使用空格符的 unicode 编码 \u0200 ref Enforcing spaces in string resources How to put space cha ...
- sharding-jdbc-how2work 当当的sharding-jdbc剖析(查询)
1. 以JDBC作为出发点 1.1 重新实现了JDBC的几个接口 实现javax.sql.DataSource接口 ShardingDataSource实现java.sql.Connection接口 ...
- mvc ajax dropdownlist onchang事件响应
<script type="text/javascript"> $("#Cycle").on("change", functio ...
- 20145320《Java程序设计》第3周学习总结
20145320<Java程序设计>第3周学习总结(第四章) 教材学习内容总结 对象(Object):存在的具体实体,具有明确的状态和行为 类(Class):具有相同属性和行为的一组对象的 ...