版本比较
P2518 [HAOI2010] 计数 题解
正文
增加 6 行删除 6 行
7 行未改动891011121312131415161738 行未改动56575859606061626363646566679 行未改动777879808181828384857 行未改动93949596979798991001014 行未改动7 行未改动#include<bits/stdc++.h>using namespace std;short len,a[51];string s;map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,long long>>>>>>>>>>> F; short cnt[10];//存每个数字需要出现的次数 map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,map<short,long long>>>>>>>>>>> F;short cnt[10];//存每个数字需要出现的次数inline long long dfs(short now_where,short if_le,short if_z,short z,short o,short t,short tr,short f,short fi,short s,short se,short e,short ni){ if(!now_where) return (o==cnt[1]&&t==cnt[2]&&tr==cnt[3]&&f==cnt[4]&&fi==cnt[5]&&s==cnt[6]&&se==cnt[7]&&e==cnt[8]&&ni==cnt[9])?1:0; else if(!if_le&&!if_z&&F[now_where][z][o][t][tr][f][fi][s][se][e].count(ni)) return F[now_where][z][o][t][tr][f][fi][s][se][e][ni]; long long ans=0,up=if_le?a[now_where]:9;38 行未改动#include<bits/stdc++.h>using namespace std;short len,a[51],cnt[10];string s,all;map<short,map<string,long long>> F; map<short,map<string,long long>> F;inline string get(short o,short t,short tr,short f,short fi,short s,short se,short e,short ni){ string nowk="";short w; w=o ;while(w) nowk+=(w%10+'0'),w/=10;nowk+=',';//加区分的字符 w=o ;while(w) nowk+=(w%10+'0'),w/=10;nowk+=',';//加区分的字符 w=t ;while(w) nowk+=(w%10+'0'),w/=10;nowk+=','; w=tr;while(w) nowk+=(w%10+'0'),w/=10;nowk+=','; w=f ;while(w) nowk+=(w%10+'0'),w/=10;nowk+=','; w=fi;while(w) nowk+=(w%10+'0'),w/=10;nowk+=',';9 行未改动 long long ans=0,up=if_le?a[now_where]:9; for(register short i=0;i<=up;++i){ if(if_z&&i==0)ans+=dfs(now_where-1,if_le&&i==up,1,0,0,0,0,0,0,0,0,0,0,""); else if(i==0) ans+=dfs(now_where-1,if_le&&i==up,0,z+1,o,t,tr,f,fi,s,se,e,ni,now); else if(i==1&&o +1<=cnt[1]) ans+=dfs(now_where-1,if_le&&i==up,0,z,o+1,t,tr,f,fi,s,se,e,ni,get(o+1,t,tr,f,fi,s,se,e,ni)); else if(i==1&&o +1<=cnt[1]) ans+=dfs(now_where-1,if_le&&i==up,0,z,o+1,t,tr,f,fi,s,se,e,ni,get(o+1,t,tr,f,fi,s,se,e,ni)); else if(i==2&&t +1<=cnt[2]) ans+=dfs(now_where-1,if_le&&i==up,0,z,o,t+1,tr,f,fi,s,se,e,ni,get(o,t+1,tr,f,fi,s,se,e,ni)); else if(i==3&&tr+1<=cnt[3]) ans+=dfs(now_where-1,if_le&&i==up,0,z,o,t,tr+1,f,fi,s,se,e,ni,get(o,t,tr+1,f,fi,s,se,e,ni)); else if(i==4&&f +1<=cnt[4]) ans+=dfs(now_where-1,if_le&&i==up,0,z,o,t,tr,f+1,fi,s,se,e,ni,get(o,t,tr,f+1,fi,s,se,e,ni)); else if(i==5&&fi+1<=cnt[5]) ans+=dfs(now_where-1,if_le&&i==up,0,z,o,t,tr,f,fi+1,s,se,e,ni,get(o,t,tr,f,fi+1,s,se,e,ni));7 行未改动}inline void solve(){ cin>>s; for(register short i=s.size()-1;i>=0;--i) a[++len]=s[i]-'0',++cnt[s[i]-'0']; all=get(cnt[1],cnt[2],cnt[3],cnt[4],cnt[5],cnt[6],cnt[7],cnt[8],cnt[9]); all=get(cnt[1],cnt[2],cnt[3],cnt[4],cnt[5],cnt[6],cnt[7],cnt[8],cnt[9]); printf("%lld",dfs(len,1,1,0,0,0,0,0,0,0,0,0,0,"")-1);//-1是减去的s这种情况,因为我们求的值s之前的数的个数}int main(){ solve();4 行未改动