当前位置:编程学习 > C/C++ >>

Zoj 2344 Toral Tickets (数学_Polya)

题目大意:给定一张有n*m个格子的纸,每个格子有黑白两种颜色可以染。现在先将纸按长边粘起来得到一个圆柱,再将纸按短边拈起来得到一个游泳圈。如果两种染色方案卷起来后是一样的,那么它们同构。问不同构的的染色方案。n,m <= 20.www.zzzyk.com

解题思路:Polya的核心是找置换,本题有两类置换,一类是滚动,一类是旋转。
    我们将n*m的纸想成一个矩阵,那么第一行是1,2,3...m,第二行是m+1...m*2,以此类推。
    第一类滚动置换有n*m个。行和列是分开的,行的滚动有n个,列的滚动有m个,它们相乘就是总置换数。每个置换的循环节个数我们就模拟下,O(n*m)找到循环节。
    第二类旋转置换要分类讨论,当n!= m时,我们可以将整个矩阵旋转180度,这里是旋转而不是翻转,我写了Rorate函数将矩阵旋转九十度,Rorate两次.当n==m时,不仅可以旋转180度,旋转90度和270度都要考虑在内。
     也就是说当n!=m时,置换有2*n*m个,当n==m时,置换有4*n*m个,再套个高精度模板就AC了。n和m很小,随便模拟。
     ac后我很ws地把结果打成表拿去提交,时间就是0s...
     高精度模板太长,我就不发上来了,百度下一坨。

测试数据:
[cpp]
"2","3","4","6","8","13","18","30","46","78","126","224", 
"380","687","1224","2250","4112","7685","14310","27012", 
"3","6","13","34","78","237","687","2299","7685","27190","96909","353384","1296858", 
"4808707","17920860","67169299","252745368","954677597","3617214681","13744852240", 
"4","13","28","224","1224","7696","50964","352698","2493784","17920860","130216124", 
"954637904","7048675960","52359294790","390941664896","2932043766538","22076502318624", 
"166800088124428","1264168584899532","9607680019329456", 
"6","34","224","1171","27012","353384","4806078","67169332","954637558","13744852240", 
"199914398490","2932046213652","43303893547956","643371617410504","9607680019329456", 
"144115191934621732","2170205198153526576","32794211748156196824","497091208931087393202","7555786373574120939544", 
"8","78","1224","27012","337664","17920860","490984488","13744694928","390941662712", 
"11259024570048","327534652572024","9607680019329456","283796066967422192","8432797316853883164", 
"251859545890487150848","7555786373422938025200","227562507225975302929472","6877444662723140842510068", 
"208495164511362678524008344","6338253001141997061913643712", 
"13","237","7696","353384","17920860","477339616","52359294790","2932046213314","166800088124428", 
"9607680171442372","558992251165454994","32794211748156896384","1937381121593132140708","115135792348177228029522", 
"6877444662723140878302528","412646679762044113662598674","24855894122123845015649413488","1502400711381621229389905570832", 
"91092927342716382903223175969098","5538449982437150493650373937210144", 
"18","687","50964","4806078","490984488","52359294790","2872202032640","643371579062292","73201367519380268","8432797316853883164", 
"981270957754284704684","115135792347575114543648","13603736695478923656694872","1616901275801738096771851776","193165805749068031447071325904", 
"23179896689887677706535219983812","2792495789464109553149422598133408","337581713215216736580493443081144242","40936224591992597182162868918208830204", 
"4977844910386299809268168657185593495464", 
"30","2299","352698","67169332","13744694928","2932046213314","643371579062292","72057595967392816","32794211738611821312", 
"7555786373574120887164","1758437555816391076574364","412646679762044113663297912","97511584632944122543696551480", 
"23179896689887687357105852460494","5538449982437150339927506647332280","1329227995784915889260880907091324992","320265757102059730540916250236523351840", 
"77433143050453552578958061549803284618034","18779574904025787908718574436155314063657516","4567192616659071619387584246010106165386598032", 
"46","7685","2493784","954637558","390941662712","166800088124428","73201367519380268","32794211738611821312","7462505059899322983424","6877444662723140842510068", 
"3201137879364778610385398532","1502400711381618810790106910044","710057690056045092131987186099464","337581713215216736580493443081144242", 
"161319048021778234678358952710942506464","77433143050453552578334971527757506752592","37313665168783264864344472097714361025020896", 
"18043230090504974298812744711929778187809121280","8751916237583886480939063648792742032126941483252","4256932057960802384328742673977943978507520207880680", 
"78","27190","17920860","13744852240","11259024570048","9607680171442372","8432797316853883164","7555786373574120887164","6877444662723140842510068","3169126500571074529242309120", 
"5900337339244149490513314759636","5538449982437150493650373937210144","5235113337245207158017777333159559848","4977844910386299809424175407065863134364","4757492309019866270222746693509250935268480", 
"4567192616659071619387584246010106137898781148","4401699048902484083060538741828788515205714226528","4256932057960802384328742835597893551876416196246244","4129672194333342607786703597714589062014181942348177028","4017345110647475688854905231971608161006919942602792622080", 
"126","96909","130216124","199914398490","327534652572024","558992251165454994","981270957754284704684","1758437555816391076574364","3201137879364778610385398532","5900337339244149490513314759636","5492677668532710795071526353530880","20623173752784149356430310745388844192", 
"38987316780647942557493557843966923142152","74142737283426487327816994675197228663038210","141721370892693616310665183118190969688269247088","27210503211397174331646810002960774611548179429828

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,