链接

这题纠结了好久,刚开始想到的是正解,不过想到可能会出现一个数支点不唯一的情况,这样就多算了,其实是我想多了,一个数只有一个支点。

这样就好像想到了,枚举支点的位置,保存力矩的状态。

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的更多相关文章

  1. HDOJ 3709 Balanced Number

    数位DP... Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java ...

  2. [HDU3709]Balanced Number

    [HDU3709]Balanced Number 试题描述 A balanced number is a non-negative integer that can be balanced if a ...

  3. hdu3709 Balanced Number (数位dp+bfs)

    Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...

  4. HDU 3709 Balanced Number (数位DP)

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  5. HDU3709 Balanced Number (数位dp)

     Balanced Number Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Descript ...

  6. 【HDU 3709】 Balanced Number (数位DP)

    Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...

  7. HDU3709:Balanced Number(数位DP+记忆化DFS)

    Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is p ...

  8. hdu 3709 Balanced Number(平衡数)--数位dp

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  9. [暑假集训--数位dp]hdu3709 Balanced Number

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

随机推荐

  1. Bootstrap 轮播插件

    一.轮播 //基本实例. <div id="myCarousel" class="carousel slide"> <ol class=&qu ...

  2. TF-IDF 文本相似度分析

    前阵子做了一些IT opreation analysis的research,从产线上取了一些J2EE server运行状态的数据(CPU,Menory...),打算通过训练JVM的数据来建立分类模型, ...

  3. http://www.cnblogs.com/ACMer/p/5170255.html

    http://www.cnblogs.com/ACMer/p/5170255.html

  4. Oracle 参数之_small_table_threshold

    SQL> select * from v$version; BANNER ------------------------------------------------------------ ...

  5. Jmeter工作原理

  6. HTTP下载文件名称编码说明

    HTTP下载保存文件名 下载文件需要保存的名称 在响应报文头中 Content-Disposition 响应报文头域中指定, 例如 Content-Disposition: attachment; f ...

  7. textarea 换行操作

    在 textarea 中输入回车符,提交表单时,传给后台的是 '\n' 或者 '\r\n'(在IE下,换行符传入\r\n:在Firefox和谷歌浏览器下,换行符只传入了\n). 楼主也做了一个案例,让 ...

  8. cocos2dx js 3.2 热更新

    COCOS IDE用手机调试更新是正常的,是预想的结果,但用COCOS IDE打包发布APK,安装到手机上,热更新下载图片.JSON UI什么的都能正常更新替换,但JS脚本没有替换,这是为毛.更新文件 ...

  9. ligerui_ligerTree_007_ligerTree动态加载节点

    ligerui:ligerTree:动态加载节点: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: 代码:json.txt ...

  10. Unity操作

    聚焦到游戏物体: Hierarchy界面选中需要聚焦的物体,双击或者使用快捷键“F”: 在Scene面板中选中物体,使用快捷键“F”   放大缩小物体: alt+鼠标右键:鼠标滑轮   从各个角度观察 ...