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. |
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;
}