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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LightOJ 1205 Palindromic Numbers

發布時間:2025/7/14 编程问答 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LightOJ 1205 Palindromic Numbers 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

數位DP。。。。



Palindromic Numbers
Time Limit:?2000MSMemory Limit:?32768KB64bit IO Format:?%lld & %llu

[Submit]?? [Go Back]?? [Status]??

Description

A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this problem you will be given two integers?i j, you have to find the number of palindromic numbers between?i?and?j?(inclusive).

Input

Input starts with an integer?T (≤ 200), denoting the number of test cases.

Each case starts with a line containing two integers?i j (0 ≤ i, j ≤ 1017).

Output

For each case, print the case number and the total number of palindromic numbers between?i?and?j?(inclusive).

Sample Input

4

1 10

100 1

1 1000

1 10000

Sample Output

Case 1: 9

Case 2: 18

Case 3: 108

Case 4: 198

Source

Problem Setter: Jane Alam Jan

[Submit]?? [Go Back]?? [Status]??



#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;typedef long long int LL;int a[70]; LL dp[70][70];LL dfs(int len,int l,int r,bool limit,bool ok) {if(l<r) return !limit||(limit&&ok);if(!limit&&~dp[len][l])return dp[len][l];LL ret=0;int mx=limit?a[l]:9;for(int i=0;i<=mx;i++){if(l==len-1&&i==0)continue;int g=ok;if(g) g=a[r]>=i;else g=a[r]>i;ret+=dfs(len,l-1,r+1,limit&&i==mx,g);}if(!limit)dp[len][l]=ret;return ret; }LL gaoit(LL n) {if(n<0) return 0;if(n==0) return 1;int len=0;while(n){a[len++]=n%10;n/=10;}LL ret=1;for(int i=len;i>=1;i--)ret+=dfs(i,i-1,0,i==len,1);return ret; }int main() {int T_T,cas=1;cin>>T_T;memset(dp,-1,sizeof(dp));while(T_T--){LL x,y;cin>>x>>y;if(x>y) swap(x,y);printf("Case %d: %lld\n",cas++,gaoit(y)-gaoit(x-1));}return 0; }


總結

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

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