返回列表 發帖

a272. 猥瑣罐頭下樓梯

本帖最後由 李知易 於 2025-2-22 00:29 編輯


本帖隱藏的內容需要回復才可以瀏覽
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long DP[20017]={0};
  4. long long f(int a){

  5.     if(a==1){
  6.         return DP[1]=1;
  7.     }if(a==2){
  8.         return DP[2]=2;
  9.     }if(DP[a]){
  10.         return DP[a];
  11.     }else{
  12.         return DP[a]= (f(a-1)+f(a-2))%10007;
  13.     }
  14. }
  15. int main()
  16. {
  17.     int a=0;
  18.     while(cin>>a){
  19.         a=a%20016;
  20.         cout<<f(a)<<endl;
  21.     }
  22.     return 0;
  23. }
複製代碼

TOP

本帖最後由 洪承廷 於 2025-2-22 11:03 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int b[20017];
  4. int compute(int a)
  5. {
  6.     if(a==1)
  7.         return 1;
  8.     else if(a==2)
  9.         return 2;
  10.     if(b[a])
  11.     {
  12.         return b[a];
  13.     }
  14.     else
  15.     {
  16.         return b[a]=(compute(a-1)+compute(a-2))%10007;
  17.     }

  18. }
  19. int main()
  20. {
  21.     int a;
  22.     while(cin>>a)
  23.     {
  24.         cout<<compute(a%20016)<<endl;
  25.     }
  26.     return 0;
  27. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long DP[20017]={0};
  4. long long f(int a){

  5.     if(n==1){
  6.         return DP[1]=1;
  7.     }if(n==2){
  8.         return DP[2]=2;
  9.     }if(DP[n]){
  10.         return DP[n];
  11.     }else{
  12.         return DP[n]= (f(n-1)+f(n-2))%10007;
  13.     }
  14. }
  15. int main()
  16. {
  17.     int n=0;
  18.     while(cin>>n){
  19.         n=n%20016;
  20.         cout<<f(n)<<endl;
  21.     }
  22.     return 0;
  23. }
複製代碼

TOP

  1. #include <bits/stdc++.h>
  2. using namespace std;

  3. long long int DP[20017]={0};
  4. long long int compute(int a)
  5. {
  6.     if(a==1)
  7.         return DP[1] = 1;
  8.     if(a==2)
  9.         return DP[2] = 2;
  10.     if(DP[a])
  11.         return DP[a];
  12.     else
  13.         return DP[a]=(compute(a-2)+compute(a-1))%10007;
  14. }
  15. int main()
  16. {
  17.     int n;
  18.     while(cin>>n)
  19.     {
  20.         n=n%20016;
  21.         cout<<compute(n)<<endl;
  22.     }
  23.     return 0;
  24. }#include <bits/stdc++.h>
  25. using namespace std;

  26. long long int DP[20017]={0};
  27. long long int compute(int a)
  28. {
  29.     if(a==1)
  30.         return DP[1] = 1;
  31.     if(a==2)
  32.         return DP[2] = 2;
  33.     if(DP[a])
  34.         return DP[a];
  35.     else
  36.         return DP[a]=(compute(a-2)+compute(a-1))%10007;
  37. }
  38. int main()
  39. {
  40.     int n;
  41.     while(cin>>n)
  42.     {
  43.         n=n%20016;
  44.         cout<<compute(n)<<endl;
  45.     }
  46.     return 0;
  47. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4.     string str;
  5.     getline(cin,str);
  6.     int space=0;
  7.     for(int i=0;i<str.length();i++)
  8.     {
  9.         if(str[i]==' ')
  10.         {
  11.            space++;
  12.         }
  13.         if(str[i]!=' ')
  14.         {
  15.             if(space%2!=0)
  16.             {
  17.                 cout<<" ";
  18.             }
  19.             cout<<str[i];
  20.             space=0;
  21.         }
  22.     }
  23.     return 0;
  24. }
複製代碼

TOP

返回列表