日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

2.3 基本算法之递归变递推 放苹果 python

發布時間:2025/3/15 python 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2.3 基本算法之递归变递推 放苹果 python 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://noi.openjudge.cn/ch0203/666/

""" 2.3 基本算法之遞歸變遞推 666 放蘋果 http://noi.openjudge.cn/ch0203/666/C和Python實現放蘋果 https://zhuanlan.zhihu.com/p/340794311Python如何實現佩爾數列? https://www.zhihu.com/question/495732022/answer/2200069561""" def putInPlate(m, n):if(m== 1 or m==0 or n==1):return 1if(m <0):return 0return putInPlate(m-n,n)+putInPlate(m,n-1)t=int(input())a = 0while a< t:m,n= map(int, input().split())if(n==0):break;print(putInPlate(m,n))a += 1

參考:

C和Python實現放蘋果
https://zhuanlan.zhihu.com/p/340794311

Python如何實現佩爾數列?
https://www.zhihu.com/question/495732022/answer/2200069561


C++代碼:

/* 2.3基本算法之遞歸變遞推_666放蘋果 http://noi.openjudge.cn/ch0203/666/1192:放蘋果 http://ybt.ssoier.cn:8088/problem_show.php?pid=1192 */ #include<iostream> #include<cstring> using namespace std; int a[20][20]; int f(int m,int n) {int i,j;for(i=1;i<=n;i++)//0個蘋果a[0][i]=1;for(i=1;i<=m;i++)//1個盤子a[i][1]=1;for(i=1;i<=m;i++)for(j=2;j<=n;j++)if(i<j)a[i][j]=a[i][i];else a[i][j]=a[i][j-1]+a[i-j][j]; } int main() {int m,n,i,j,k;cin>>k;for(i=1;i<=k;i++){cin>>m>>n;f(m,n);cout<<a[m][n]<<endl;}return 0; }

總結

以上是生活随笔為你收集整理的2.3 基本算法之递归变递推 放苹果 python的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。