题解 P4484 【[BJWC2018]最长上升子序列】

· · 题解

dfs+打表!!!!!!

看一眼数据,n<=28,这不就是打表嘛

容易想到,先打个爆搜,让他自己跑

例如这样:

伪代码附上

#include<bits/stdc++.h>
using namespace std;
void dfs(int x){
  if(...){...}
  for(...){
  if(...){
  ...
    }
    }

}
int main(){
  for(int i = 1;i <= n;i++){
    dfs(i);                   
  }
}

我自己用dfs跑了一个早上,总算跑完了28个!!!

下面,正片环节到了

打表代码附上

#include<bits/stdc++.h>
using namespace std;
int n,f[30]={19260817, 1,499122178,2,915057326,540715694,
         946945688,422867403,451091574,317868537,200489273,
         976705134,705376344,662845575,331522185,228644314,262819964,
         686801362,495111839,947040129,414835038,696340671,749077581,301075008,
         314644758,102117126,819818153,273498600,267588741}; 
int main(){
    cin>>n;
    cout<<f[n];
}