日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

HDOJ 3709 Balanced Number

發布時間:2025/4/14 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDOJ 3709 Balanced Number 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數位DP。。。

Balanced Number

Time Limit: 10000/5000 MS (Java/Others)????Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1337????Accepted Submission(s): 583


Problem DescriptionA balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box with weight indicated by the digit. When a pivot is placed at some digit of the number, the distance from a digit to the pivot is the offset between it and the pivot. Then the torques of left part and right part can be calculated. It is balanced if they are the same. A balanced number must be balanced with the pivot at some of its digits. For example, 4139 is a balanced number with pivot fixed at 3. The torqueses are 4*2 + 1*1 = 9 and 9*1 = 9, for left part and right part, respectively. It's your job
to calculate the number of balanced numbers in a given range [x, y].
InputThe input contains multiple test cases. The first line is the total number of cases T (0 < T ≤ 30). For each case, there are two integers separated by a space in a line, x and y. (0 ≤ x ≤ y ≤ 1018).
OutputFor each case, print the number of balanced numbers in the range [x, y] in a line.
Sample Input2
0 9
7604 24324
Sample Output10
897
AuthorGAO, Yuan
Source2010 Asia Chengdu Regional Contest
Recommendzhengfeng?

#include?<iostream>
#include?<cstdio>
#include?<cstring>

using?namespace?std;

typedef?long?long?int?LL;

LL?x,y,dp[20][20][2000];
int?bit[20];

LL?dfs(int?pos,int?o,int?sum,int?limit)
{
????if(sum<0)?return?0;
????if(pos==-1)?return?sum==0;
????if(!limit&&~dp[pos][o][sum])?return?dp[pos][o][sum];
????int?end=limit?bit[pos]:9;
????LL?ans=0;
????for(int?i=0;i<=end;i++)
????{
????????ans+=dfs(pos-1,o,sum+i*(pos-o),limit&&i==end);
????}
????if(!limit)
????????dp[pos][o][sum]=ans;
????return?ans;
}

LL?calu(LL?x)
{
????int?pos=0;
????while(x)
????{
????????bit[pos++]=x%10;
????????x/=10;
????}
????LL?ans=0;
????for(int?o=0;o<pos;o++)
????{
????????ans+=dfs(pos-1,o,0,true);
????}
????return?ans-pos;
}

int?main()
{
????int?t;
????scanf("%d",&t);
????memset(dp,-1,sizeof(dp));
????while(t--)
????{
????????scanf("%I64d%I64d",&x,&y);
????????printf("%I64d\n",calu(y)-calu(x-1));
????}
????return?0;
}
* This source code was highlighted by?YcdoiT. ( style: Codeblocks )


轉載于:https://www.cnblogs.com/CKboss/p/3350826.html

總結

以上是生活随笔為你收集整理的HDOJ 3709 Balanced Number的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。