• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

2019.7.19 义乌模拟赛 T1 A

开发技术 开发技术 6小时前 4次浏览

打表天下第一不接受反驳
这里讲不打表做法吧。
我们考虑枚举一个数算出另一个数的贡献。
然后这个还不太好算我们再枚举一维长度。
我们将所有长度为当前长度的子串加入AC自动机中,并限制一旦走到长度为当前长度的节点就不能走下去。
那么就可以愉快地数位dp了。
时间复杂度大概是(O(5^3n))
代码就写了个打表。

#include<bits/stdc++.h>
#define I inline
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define re register
#define ll long long
#define db double
#define N 500000
#define M 50000
#define mod 1000000000
#define mod2 39989
#define eps (1e-7)
#define U unsigned int
#define it iterator
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x ))
using namespace std;
int n,A[N+5],Ah,B[N+5],Bh,dp[10][10];ll ans;
ll C[1005]={0,3326,24076,56698,101192,157558,225796,305906,397888,501742,617617,782939,957887,1177187,1417471,1678739,1960991,2264227,2588447,2933651,3298387,3632591,4060273,4407239,4814971,5243687,5693387,6164071,6655739,7168391,7700199,8202227,8798755,9414529,9933513,10529677,11146825,11784957,12444073,13124173,13823053,14492905,15256881,16041841,16845707,17536709,18321305,19126885,19953449,20800997,21666949,22504625,23436049,24388457,25361849,26353807,27216827,28189855,29183867,30198863,31231887,32237387,33336259,34456115,35596955,36758779,37938829,38973867,40135327,41317771,42517867,43691191,44957511,46244815,47553103,48882375,50232631,51600773,52807829,54157721,55524889,56866037,58299805,59754557,61230293,62727013,64244717,65783405,67339639,68718713,70252953,71761925,73363141,74985341,76628525,78292693,79977845,81683981,83411101,85155427,86703282,88480336,90323250,92375912,94468574,96601236,98773898,100986560,103239222,105531884,107860704,110085478,111968776,114147668,116366560,118625452,120924344,123263236,125642128,128061020,130517652,132969146,135386374,137794412,140404246,143054080,145743914,148473748,151243582,154053416,156898248,159569192,162226700,165031484,167698484,170567732,173476980,176426228,179415476,182444724,185508932,188399326,191294352,194321316,197385510,200311472,203440134,206608796,209817458,213066120,216349704,219459548,222592092,225838470,229124848,232448452,235633376,239021452,242449528,245917604,249420564,252749858,256119920,259585712,263091504,266637296,270220310,273664196,277311686,280999176,284721512,288270256,291877836,295563042,299288248,303053454,306858660,310701084,314403932,318310836,322252548,326020742,329865840,333770460,337715080,341699700,345724320,349788940,353890774,357852584,362013672,366001316,370083932,374207966,378372000,382576034,386820068,391104102,395428136,399789380,403991944,407713978,412142464,415961802,420115164,424308526,428541888,432815250,437128612,441481974,445879648,450528012,455236260,459839452,464646114,469492776,474379438,479306100,484272762,489279424,494308580,498704708,503676354,507551180,511926484,516341788,520797092,525292396,529827700,534403004,539015498,543755024,548945532,553572758,558171998,563101946,568071894,573081842,578131790,583221738,588343886,593302864,598712784,603582576,608705188,613563390,618752752,623982114,629251476,634560838,639902362,645080792,650710124,655817434,661164512,666546534,671663698,677112474,682601250,688130026,693690926,699088808,704937552,710282380,715848872,721455364,727096796,732472922,738181112,743929302,749709578,755326912,761395068,766977414,772763320,778589226,784455132,790355974,795991062,801958666,807958318,813795104,820082672,825902536,831907856,837953176,844038496,850163816,856324068,862218118,868437146,874493384,881000364,887057746,893282480,899547214,905851948,912196682,918581416,925001078,931129142,936785558,943289246,949814528,955610290,961864352,968158414,974492476,980866538,987280600,993738530,1000448072,1007093890,1014283302,1020861260,1027768622,1034715984,1041703346,1048730708,1055798070,1062897192,1069834024,1077220886,1084118088,1090933564,1098060340,1105227116,1112433892,1119680668,1126967444,1134270488,1140827006,1147970006,1155134086,1161000440,1167572156,1174183872,1180835588,1187527304,1194259020,1201027376,1208049814,1215527804,1223036178,1229873402,1236663844,1243913906,1251203968,1258534030,1265904092,1273303556,1280545446,1288242850,1295970636,1303052712,1310493152,1317542556,1325052032,1332601508,1340190984,1347809824,1355271166,1363187984,1371135182,1378454776,1386121968,1393821818,1401130184,1408899074,1416707964,1424546180,1432226974,1440363206,1448529816,1456086928,1463973534,1471900140,1479859400,1487426728,1495455032,1503512624,1511412870,1519768516,1528154538,1535949168,1544055188,1552201208,1560387228,1568605898,1576432188,1584709156,1592828854,1601403914,1610009348,1618041496,1626366930,1634732364,1643137798,1651583232,1660061312,1668114876,1675705674,1684270062,1692874450,1701496528,1709268714,1717623476,1726018238,1734453000,1742927762,1751445948,1760216668,1768794726,1778052414,1787340280,1795893004,1804901066,1813949128,1823037190,1832165252,1841322314,1850322606,1859767886,1868604906,1878112184,1886902426,1896129902,1905397378,1914704854,1924052330,1933428768,1942648512,1952323330,1962028020,1971114176,1980141936,1989588826,1999075716,2008602606,2018169496,2027746428,2036463336,2045762748,2055102160,2064458674,2072316556,2081084684,2089892812,2098740940,2107629068,2116553286,2125858636,2135616740,2145414844,2155241084,2164288306,2173269950,2182840126,2192450302,2202100478,2211777258,2221302060,2231279578,2241297096,2251342748,2260637108,2270395376,2279635982,2289465572,2299335162,2309231318,2318975572,2329172504,2339409436,2349674500,2359206378,2369193684,2379211362,2388710930,2398799934,2408915466,2418879172,2429295518,2439751864,2450236340,2460005736,2470212456,2480459176,2490736264,2500494794,2510829702,2521012860,2531648620,2542324380,2553028268,2563035182,2573461316,2583927450,2594433584,2604970082,2614949146,2624474326,2635099414,2645764502,2656469590,2667188464,2676937074,2687392536,2697887998,2708423460,2719001902,2729833800,2740344098,2751662486,2763020874,2774407194,2784934684,2796043446,2807192208,2818380970,2829595972,2840659724,2852163422,2862932682,2874510484,2886116216,2896881224,2908209400,2919577576,2930985752,2942420130,2953703334,2965438852,2977201960,2988230182,3000055326,3011057852,3022605442,3034193032,3045820622,3057474376,3068977032,3080931964,3092926896,3104949414,3116224524,3127464568,3139231572,3151038576,3162885580,3174736400,3185613698,3197069522,3208565346,3220101170,3231650118,3241499528,3252464068,3263468608,3274513148,3285593228,3297181490,3309219708,3321297926,3333416144,3345560250,3356817470,3367990316,3379880606,3391810896,3403764992,3415572706,3427830338,3440127970,3452465602,3464829120,3476335764,3488411860,3499843668,3511993372,3524166844,3536194010,3548671056,3561188102,3573745148,3586328078,3598072240,3610379660,3622715166,3634405936,3646798784,3659045402,3671741862,3684478322,3697254782,3710057124,3722038804,3734565638,3747132472,3759727388,3771631952,3783091514,3795777302,3808503090,3821268878,3834074666,3846890336,3858615370,3871171532,3883767694,3896406392,3909299468,3921742006,3935121094,3948540182,3961999270,3975484044,3987986300,4001195762,4014445224,4027718166,4040845378,4054407494,4067108994,4080747496,4094425998,4108130184,4120869958,4134298834,4147767710,4161260028,4174606692,4188402910,4202224436,4215184898,4229082814,4243006412,4255983704,4269631994,4283320284,4297031978,4310598094,4324613726,4338669358,4352750294,4365969718,4380112728,4393327538,4407195242,4421102946,4435034016,4448819584,4463054630,4477329676,4491644722,4505985068,4519449132,4532901460,4546988578,4561115696,4575240404,4588278092,4601890328,4615542564,4629234800,4642967036,4656708418,4668549356,4681710308,4694911260,4708147202,4722018376,4736336708,4750695040,4765093372,4779531704,4793993676,4807460894,4820824942,4835035346,4849266758,4863357384,4877895130,4892472876,4907090622,4921748368,4936429752,4950148680,4964542604,4978165614,4992616402,5006926480,5021683640,5036480800,5051317960,5066195120,5081095916,5095052362,5109679896,5124333230,5138163294,5151557238,5166303726,5181090214,5195916702,5210783190,5225689678,5240602144,5254303602,5268960464,5283659418,5298613672,5312988450,5328428238,5343908026,5359427814,5374987602,5390570830,5405047852,5420358014,5435688896,5450879568,5466500102,5481133842,5496833044,5512572246,5528351448,5544154088,5558868628,5574398204,5589948462,5605358586,5621215504,5637095448,5651988150,5667946766,5683945382,5699967434,5714919492,5730668482,5746438116,5762067692,5778144024,5794260356,5810399710,5825551374,5841769404,5858010868,5873200444,5889168848,5905157858,5921006886,5937302632,5953638378,5970014124,5986412888,6001823514,6018284390,6033711484,6049899302,6066107688,6082176168,6098691328,6115246488,6131841648,6148476808,6165134982,6180788000,6196452612,6212859844,6229258440,6244456518,6260225166,6276033814,6291882462,6307771110,6323699758,6339633574,6353466040,6368823404,6384215208,6400369294,6416967740,6433606186,6450284632,6467003078,6483761524,6500541362,6516218578,6531773828,6548282556,6564656094,6581473954,6598331814,6615229674,6632167534,6649145394,6666144644,6682075856,6698787608,6714543172,6729871498,6746678686,6763525874,6780413062,6797340250,6814307438,6831314626,6848323888,6864001770,6880760980,6897776412,6914083430,6931583918,6949124406,6966704894,6984325382,7001985870,7019667552,7036119340,7053508162,7070762294,7088441246,7105007226,7122767128,7140567030,7158406932,7176286834,7194187928,7210877234,7228485432,7245959016,7263876634,7281814996,7298639938,7316659254,7334718570,7352817886,7370938392,7387865216,7405692790,7423385826,7441522858,7459699890,7477897662,7494981566,7513260296,7531579026,7549918944,7567083286,7585130236,7603042724,7621399170,7639795616,7658232062,7676689244,7694032110,7712570254,7731129584,7748531444,7766797770,7784929710,7803505570,7822121430,7840777290,7859473150,7878189742,7895791570,7914570312,7932209690,7950695392,7969046784,7987842058,8006677332,8025552606,8044467880,8063423154,8082399156,8100241128,8118118024,8136790508,8154148976,8172074036,8190039096,8208044156,8226089216,8244174276,8262299336,8280425586,8296249580,8313797246,8332234244,8351112804,8370031364,8388989924,8407988484,8427027044,8446105604,8465203308,8483090522,8500771586,8518034294,8536902182,8555810070,8574757958,8593745846,8612773734,8631841622,8650949510,8670055568,8687711078,8706787688,8725026946,8744588134,8764189322,8783830510,8803511698,8823232886,8842994074,8862774210,8881175964,8900493556,8920230926,8938729146,8958549748,8978410350,8998310952,9018251554,9038232156,9058231704,9076870938,9096407982,9116386300,9136383080,9155140262,9175220278,9195340294,9215500310,9235700326,9255919286,9274796000,9294552496,9314750228,9334987960,9355244150,9374260294,9394599724,9414979154,9435398584,9455836956,9474951150,9494927098,9515344244,9535801390,9556298536,9576814136,9596089242,9616688086,9637326930,9657984714,9677336388,9697531788,9718168348,9738844908,9759561468,9780318028,9801093038,9820627106,9841485364,9862362560,9881951714,9902366566,9923222540,9944118514,9965054488,9986030462,10007046436,10028080856,10047873886,10068970494,10088797128,10109431432,10130506820,10151622208,10172777596,10193972984,10215208372,10236483760,10257777590,10277808516,10297836608,10317355466,10337436938,10357558410,10377719882,10397921354,10418162826,10438444298,10458765770,10479084454,10496858675};
I int calc(int x,int y){
	re int i,j,ans=0,tot=0,now;Ah=Bh=0;while(x)A[++Ah]=x%10,x/=10;while(y) B[++Bh]=y%10,y/=10; 
	for(i=1;i<=Ah;i++){
		for(j=1;j<=Bh;j++) dp[i][j]=((A[i]==B[j])?dp[i-1][j-1]+1:0),ans=max(ans,dp[i][j]);
	}
	return ans;
}
int main(){
	freopen("diyiti.in","r",stdin);freopen("diyiti.out","w",stdout);
	re int i,j;scanf("%d",&n);ans=C[n/100];
	for(i=n/100*100+1;i<=n;i++){
		for(j=1;j<i;j++) ans+=calc(i,j)*2;ans+=calc(i,i);
	}printf("%lldn",ans); 
} 

程序员灯塔
转载请注明原文链接:2019.7.19 义乌模拟赛 T1 A
喜欢 (0)