正解:数位$dp$
解题报告:
$HNOI$的题从02年就这么神了嘛$QAQ$,,,
嗷对了这题如果看出了一个结论就是个数位$dp$板子,,,?但是结论很神我$jio$得挺难看出来的_(:з」∠)_
先港结论,,,,$f_{i}$等于$i$的二进制下翻转之后的值,即$f((\overline{a_{1}a_{2}a_{3}a_{4}a_{5}})_2)=(\overline{a_{5}a_{4}a_{3}a_{2}a_{1}})_2$,,,这谁想得到啊$TT$
下试证$QwQ$
考虑数学归纳法,不难发现当$i=1,2,3$时都成立
然后对于$n=2\cdot k$,显然有$f_{n}=1$,显然依然成立
对于$n=4\cdot k+1$,设$k=(\overline{a_{1}a_{2}a_{3}a_{4}a_{5}})_2$,则$2\cdot k+1=(\overline{a_{1}a_{2}a_{3}a_{4}a_{5}1})_2,4\cdot k+1=(\overline{a_{1}a_{2}a_{3}a_{4}a_{5}01})_2$,所以有$f(n)=2\cdot (\overline{1a_{5}a_{4}a_{3}a_{2}a_{1}})_2-(\overline{a_{5}a_{4}a_{3}a_{2}a_{1}})_2=(\overline{1a_{5}a_{4}a_{3}a_{2}a_{1}})_{2}+((\overline{1a_{5}a_{4}a_{3}a_{2}a_{1}})_{2}-(\overline{a_{5}a_{4}a_{3}a_{2}a_{1}})_2)=(\overline{10a_{5}a_{4}a_{3}a_{2}a_{1}})_{2}$,成立
对于$n=4\cdot k+3$,同理地设$k=(\overline{a_{1}a_{2}a_{3}a_{4}a_{5}})_2$,则$2\cdot k+1=(\overline{a_{1}a_{2}a_{3}a_{4}a_{5}1})_2,4\cdot k+3=(\overline{a_{1}a_{2}a_{3}a_{4}a_{5}11})_2$,所以有$f(n)=3\cdot (\overline{1a_{5}a_{4}a_{3}a_{2}a_{1}})_2-2\cdot (\overline{a_{5}a_{4}a_{3}a_{2}a_{1}})_2=(\overline{1a_{5}a_{4}a_{3}a_{2}a_{1}})_2+2\cdot ((\overline{1a_{5}a_{4}a_{3}a_{2}a_{1}})_2-(\overline{a_{5}a_{4}a_{3}a_{2}a_{1}})_2)=(\overline{11a_{5}a_{4}a_{3}a_{2}a_{1}})_{2}$,依然成立
综上,证毕
欧克现在证完了就继续思考这题怎么做趴$QwQ$
首先显然把$m$转换成二进制${m}'$,然后现在就变成了,询问在${m}'$以内的所有二进制数有多少个是回文数
$umm$其实感觉到这儿了乱搞应该也能做出来辣,,,?但我还是大概港下数位$dp$做法趴$kk$
$umm$其实就差不多的套路,,,?因为我数位$dp$比较喜欢用$dfs$那种的就只港下$dfs$版怎么做鸭$QwQ$
首先显然考虑记录一个$pos$,一个$lim$,然后因为这题是要判断回文,所以显然要有个$bool$变量记录是否是回文,然后还有一个点就是,比如有这种情况:$00011$,如果直接判断就不是个回文数了,所以要考虑再记录一个实际位数,瞎判下就好
所以总共就记录四个变量,然后套路地做下就好
嗷还有一个,这题真的$real$奇葩,,,还强行加了个高精,,,读入还要强行高精转进制,,,神烦,,,我要死了$TT$
所以并不推荐用这题练习数位$dp$($bushi$
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
#define il inline
#define lf double
#define fi first
#define sc second
#define gc getchar()
#define mp make_pair
#define ri register int
#define rb register bool
#define rc register char
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i) const int N=+,M=+;
int a[N],cnt,tmp[N],vis[N][N][],lst=,qaq;
struct big_int
{
int num,a[M];
il void reve(ri l,ri r){while(l<r){swap(a[l],a[r]);++l;--r;}}
il void read(){char str=gc;while(str>'' || str<'')str=gc;while(str>='' && str<='')a[++num]=str^'',str=gc;reve(,num);}
big_int(){num=;memset(a,,sizeof(a));}
void operator = (int x){while(x)a[++num]=x%,x/=;}
il void print(){if(!num)return void(printf("0\n"));my(i,num,)printf("%d",a[i]);printf("\n");}
}as,f[N][N][],tmpp; il big_int operator + (big_int gd,big_int gs)
{gd.num=max(gd.num,gs.num);rp(i,,gd.num){gd.a[i]=gd.a[i]+gs.a[i]+gd.a[i-]/;gd.a[i-]%=;if(i==gd.num && gd.a[i]>)++gd.num;}return gd;}
il big_int operator / (big_int gd,int gs)
{
big_int ret;ri x=;
my(i,gd.num,){ret.a[i]=(gd.a[i]+x*)/gs;x=(x*+gd.a[i])%gs;}
ret.num=gd.num;while(ret.num && !ret.a[ret.num])--ret.num;return ret;
}
il int operator % (big_int gd,int gs){ri x=;my(i,gd.num,)x=(x*+gd.a[i])%gs;return x;}
il big_int solve(ri num,ri pos,rb jud,rb lim)
{
big_int ret;ret=;if(pos<){if(jud && num)ret=;return ret;}if(!lim && vis[pos][num][jud])return f[pos][num][jud];if(!jud)return ret;
ri mx=lim?a[pos]:;
rp(i,,mx)
{
tmp[pos]=i;
if(pos==num && !i)ret=ret+solve(num-,pos-,jud,lim && i==mx);
else ret=ret+solve(num,pos-,(jud && pos<=num/)?tmp[num-pos+]==i:jud,lim && i==mx);
}
if(!lim)vis[pos][num][jud]=,f[pos][num][jud]=ret;
return ret;
} int main()
{
freopen("2235.in","r",stdin);freopen("2235.out","w",stdout);
tmpp.read();while(tmpp.num){a[++cnt]=tmpp%;tmpp=tmpp/;}
as=solve(cnt,cnt,,);as.print();
return ;
}