1137人阅读 评论(0)

# number number number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26    Accepted Submission(s): 13

Problem Description
We define a sequence F:

F0=0,F1=1;
Fn=Fn1+Fn2 (n2).

Give you an integer k, if a positive number n can be expressed by
n=Fa1+Fa2+...+Fak where 0a1a2ak, this positive number is mjfgood. Otherwise, this positive number is mjfbad.
Now, give you an integer k, you task is to find the minimal positive mjfbad number.

Input
There are about 500 test cases, end up with EOF.
Each test case includes an integer k which is described above. (1k109)

Output
For each case, output the minimal mjfbad number mod 998244353.

Sample Input
1

Sample Output
4

Source
【题意】：

【解析】：

【代码】

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define mset(a,i) memset(a,i,sizeof(a))
using namespace std;
typedef long long ll;
const int mod=998244353;
ll qpow(ll n,ll m){n%=mod;ll ans=1;while(m){if(m%2)
ans=(ans*n)%mod;m/=2;n=(n*n)%mod;}return ans;}
struct zhen{
int r,c;//行列始于1
ll a[16][16];
zhen(int R=0,int C=0){
memset(a,0,sizeof(a));
r=R;c=C;
}
};
zhen operator*(zhen A,zhen B)//矩阵A*B
{
zhen C(A.r,B.c);
for(int i=1;i<=A.r;i++)
for(int j=1;j<=B.c;j++)
for(int k=1;k<=A.c;k++){
C.a[i][j]+=((A.a[i][k]+mod)*(mod+B.a[k][j]))%mod;
C.a[i][j]%=mod;
}
return C;
}
zhen qpow(zhen A,ll m)//方阵A的m次幂
{
zhen ans(A.r,A.c);
for(int i=1;i<=A.r;i++) ans.a[i][i]=1;//单位矩阵
while(m)
{
if(m%2)ans=ans*A;
A=A*A;
m/=2;
}
return ans;
}
int main()
{
ll n;
while(cin>>n)
{
if(n==1){
puts("4");continue;
}
if(n==2){
puts("12");continue;
}
zhen A(3,3);//构造矩阵A
A.a[1][1]=3;
A.a[1][3]=A.a[2][1]=A.a[3][3]=1;
A.a[1][2]=-1;
//矩阵A构造完毕
//所以 Xn+1 = A^(n-2) * X3;
zhen X3(A.r,1),X;
X3.a[1][1]=12;
X3.a[2][1]=4;
X3.a[3][1]=1;
X=qpow(A,n-2)*X3;
ll ans=X.a[1][1];
cout<<ans%mod<<endl;
}
}  

#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long ll;
int dp[200][2000];
int main()
{
ll c[1100]={0,1,1};
for(int i=2;i<1020;i++)
c[i]=(c[i-1]+c[i-2]);
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i <= 40; i++)     //枚举总类
{
for (int num = 1; num <= 40; num++)    //枚举个数
{
for (int j = c[i]; j <= 1000; j++)      //枚举容量
{

dp[num][j] += dp[num - 1][j - c[i]];
}
}
}
for(int i=0;i<=40;i++)
for(int j=1;j<=1000;j++)
if(dp[i][j]==0)
{
printf("%d\n",j);break;
}
return 0;
}

个人资料
等级：
访问量： 10万+
积分： 3136
排名： 1万+
博客专栏
 ACM荣耀之路 文章：97篇 阅读：47288 ACM算法 文章：24篇 阅读：7408
最新评论