4 条题解

  • 0
    @ 2024-4-12 21:02:00

    #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int>su(n+1); for (int i = 1; i <= n; i++)cin >> su[i]; int way[1001]; way[1] = 0; way[2] = 1; way[3] = 2; for (int i = 1; i <= n; i++) { for (int j = 4; j <= su[i]; j++) way[j] = way[j - 1] + way[j - 2]; cout << way[su[i]] << endl; }

    return 0;
    

    }

    • 0
      @ 2024-4-12 16:01:32
      #include <bits/stdc++.h>
      using namespace std;
      int dp[N]={0};
      signed main(){
      	int count;
      	dp[1]=1;
      	dp[2]=1;
      	cin>>count;
      	
      	for(int i=3;i<51;i++){
      		dp[i]=dp[i-1]+dp[i-2];
      	}
      	for(int i=0;i<count;i++){
      		int x;
      		cin>>x;
      		cout<<dp[x]<<endl;
      	}
      
      	return 0;
      }
      
      • 0
        @ 2024-4-12 10:19:05
        import java.util.Scanner;
        
        public class Main {
        
            public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
        
                int n=sc.nextInt();  //次数为n
                int[] m=new int[n];
        
                for (int i = 0; i < n; i++) {
                    m[i]=sc.nextInt()-1;
                }
                int[][] dp=new int [n][45];
        
                for (int i = 0; i < n; i++) {
                    dp[i][0]=1;
                    dp[i][1]=1;
                    dp[i][2]=2;
                }
        
        
                for (int i = 0; i < n; i++) { //次数
                    for (int j = 2; j <= m[i]; j++) {  //
                        dp[i][j]=dp[i][j-1]+dp[i][j-2];
                    }
                }
        
                for (int i = 0; i < n; i++) {
                    System.out.println(dp[i][m[i]]);
                }
            }
        }
        
        • 0
          @ 2024-4-8 16:18:39
          for i in range(int(input())):
              m = int(input())
              dp = [0]*50
              dp[1] =1 
              dp[2] =1 
              for i in range(3,45):
                  dp[i] = dp[i-1]+dp[i-2]
                  
              print(dp[m])
          
          • 1

          信息

          ID
          129
          时间
          1000ms
          内存
          256MiB
          难度
          5
          标签
          递交数
          296
          已通过
          114
          上传者