Luogu: P1255 counting stairs (backtracking, high-precision addition)

topic:

Insert picture description here

Analysis: No need to analyze: Just pay attention to your thoughts. Similar to dp, big problems will not be solved. Small problems will be solved slowly until the big problems are solved.

This question is mainly due to insufficient size. Use high-precision addition.

Code:

#include<bits/stdc++.h>
using namespace std;
int A[5005][5005];
int main()
{
    
    
 //
 A[1][1]=1; 
 A[2][1]=2;
 int m; cin>>m;
 int len=1;
 for(int i=3;i<=m;i++)
 {
    
    
  for(int j=1;j<=len;j++)
  {
    
    
   A[i][j]+=A[i-1][j]+A[i-2][j];
   if(A[i][j]<10) continue;
   A[i][j]=A[i][j]%10;
   A[i][j+1]++;
   if(j==len) len++;
  }
 }
 for(int i=len;i>=1;i--)
 {
    
    
  cout<<A[m][i];
 }
}

The high accuracy is also very simple, it just needs to use a changing value to record how many bits there are.

len is the changed value, and the setting len here is very good:

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42721412/article/details/108475270