hdu5351(2015多校5)--MZL's Border(打表,,找規律)

來源:互聯網
上載者:User

標籤:

題目連結:點擊開啟連結

題目大意:給出b1 = ‘b‘ , b2 = ‘a‘ , bi = b(i-1)b(i-2),將i-1和i-2連結起來,記錄一個串的s[1~i] 和s[n-i+1~n]相同的話

Border,當i為最長是為LBorder,現在給讓求在bn這個串上的前m個字元組成的子串的LBorder

通過計算可以發現,b字串的首碼都是相同的,所以只要求出m的LBorder就行,和n是無關的,打表找出規律,找出對應不同的m,LBorder的值,因為存在大數,用java寫

dp[i]第i層開頭的數字大小

dp[1] = 0 ;

dp[2] = 0 ;

dp[i] = dp[i-1] + dp[i-2] + 1;

len[i]第i層的長度

len[i] = dp[i+1] + 1 ;

這是n等於15時的表


import java.util.*;import java.math.* ;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in) ;        BigInteger dp[] = new BigInteger[1100] ;        BigInteger len[] = new BigInteger[1100] ;        BigInteger m , t0 , t1 , Mod , x , y  ;        t0 = new BigInteger("0") ;        t1 = new BigInteger("1") ;        Mod = new BigInteger("258280327") ;        int t , n , i , j ;        dp[1] = t0 ;        dp[2] = t0 ;        len[0] = t0 ;        len[1] = t1 ;                for(i = 3 ; i <= 1010 ; i++) {            dp[i] = t1.add( dp[i-1].add(dp[i-2]) ) ;            len[i-1] = len[i-2].add( dp[i].add(t1) ) ;        }        /*        System.out.println( Mod );        for(i = 1 ; i <= 10 ; i++)            System.out.println( len[i] );        */        t = cin.nextInt() ;        for(i = 0 ; i < t ; i++){            n = cin.nextInt() ;            m = cin.nextBigInteger() ;            for(j = 1 ; j <= 1010 ; j++) {                int k = m.compareTo(len[j]) ;                if( k == -1 || k == 0 ) {                    break ;                }            }            m = m.subtract(len[j-1]) ;            m = m.add(dp[j]) ;            m = m.subtract(t1) ;            m = m.remainder(Mod) ;            System.out.println( m );        }    }}


Border

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

hdu5351(2015多校5)--MZL's Border(打表,,找規律)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.