hnu 13015 Buses


Buses
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 4, Accepted users: 2
Problem 13015 : No special judgement
Problem description

Programming competitions usually require infrastructure and organization on the part of thoseresponsible. A problem that frequently must be solved is regarding transportation. While participatingin a recent competition, Ricardinho watched the buses and micro-buses used in the transportation ofcompetitors, all lined up one behind the other as competitors disembarked. The vehicles were all fromthe same company, although had di erent paintings. Ricardinho began to wonder how many waysthat line could be formed using buses and minibuse from that company.
Each bus is 10 meters long, each minibus is 5 meters long. Given the total length of a line of busesand minibuses, and the number of di erent colors each buse or minibus may be painted, Ricardinhowants to know in how many ways such a line can be formed.


Input

The input contains a single line, containing three integers N;K and L, representing respectively thetotal length, in meters, of the line Ricky is considering, K indicates the number of di erent colors formicro-buses, and L represents the number of di erent colors for buses. Note that, as integers N, Kand L may be very large, the use of 64 bits integers is recommended.


Output

As the number of di erent ways of forming the line can be very large, Ricardinho is interested in thelast 6 digits of that quantity. Thus, your program should produce a single line containing exactly 6digits, corresponding to the last digits of the solution.


Sample Input
25 5 5
5 1000 1000
20 17 31
Sample Output
006000
001000
111359


每辆bus10米长  迷你bus5米长  给出N米  Bus的总长度

迷你bus有k种颜色  bus有l种颜色 

求他们能组成的最多的组合数(主要输出最后的六位数  所以我们每次求值时可以mod 1000000)

将5米作为一个长度单位  当只有一个长度单位时  就是只有一辆迷你Bus  组合数就是k

两个长度单位时就是k*k+l

大于等于两个长度单位时通过构造矩阵来求

|k l|

|1 0|  构造这样的初始矩阵 

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>

#define eps 1e-8
#define op operator
#define MOD  1000000
#define MAXN  100100
#define INF 0x7fffffff

#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define FOV(i,a,b)  for(int i=a;i>=b;i--)
#define REP(i,a,b)  for(int i=a;i<b;i++)
#define REV(i,a,b)  for(int i=a-1;i>=b;i--)
#define MEM(a,x)    memset(a,x,sizeof a)
#define ll __int64

using namespace std;

const ll mod=1000000;
struct matrix
{
    ll a[2][2];
};

matrix ori,res;

void init()
{
    memset(res.a,0,sizeof(res.a));
    for(int i=0;i<2;i++)
        res.a[i][i]=1;
}

matrix multiply(matrix x,matrix y)
{
    matrix temp;
    memset(temp.a,0,sizeof(temp.a));
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            for(int p=0;p<2;p++)
            {
                temp.a[i][j]+=(x.a[i][p]*y.a[p][j]);
                temp.a[i][j]%=mod;
            }
        }
    }
    return temp;
}

void calc(ll num)
{
    while(num)
    {
        if(num&1)
            res=multiply(ori,res);
        num>>=1;
        ori=multiply(ori,ori);
    }
//    for(int i=0;i<n;i++)
//    {
//        for(int j=0;j<n;j++)
//            cout<<res.a[i][j]<<"\t";
//        cout<<endl;
//    }
}



int main()
{
//freopen("ceshi.txt","r",stdin);
    ll n,k,l;
    while(scanf("%I64d%I64d%I64d",&n,&k,&l)!=EOF)
    {
        n/=5;
        ori.a[0][0]=k%mod;
        ori.a[0][1]=l%mod;
        ori.a[1][0]=1;
        ori.a[1][1]=0;
        ll xx=(k%mod);//只有一个单位长度
        ll yy=(((k%mod)*(k%mod))%mod+l%mod)%mod;//只有两个单位长度
//        y%=mod;
        if(n==1)
        {
            printf("%06d\n",(int)xx);
//            continue;
        }
        else
        {
            if(n==2)
            {
                printf("%06d\n",(int)yy);
//                continue;
            }
            else
            {
                init();
                calc(n-2);
                ll ans=(res.a[0][0]*yy%mod+res.a[0][1]*xx%mod)%mod;
//                ans%=mod;
                printf("%06d\n",(int)ans);
            }
        }
    }
    return 0;
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值