1011 数的计算
題目描述?Description
我們要求找出具有下列性質數的個數(包含輸入的自然數n):
先輸入一個自然數n(n<=1000),然后對此自然數按照如下方法進行處理:
1.??????????不作任何處理;
2.??????????在它的左邊加上一個自然數,但該自然數不能超過原數的一半;
3.??????????加上數后,繼續按此規則進行處理,直到不能再加自然數為止.
?
輸入描述?Input Description一個數n
?
輸出描述?Output Description滿足條件的數的個數
?
樣例輸入?Sample Input6
樣例輸出?Sample Output6
?
數據范圍及提示?Data Size & Hint6個數分別是:
6
16
26
126
36
136
遞推!!
?
AC代碼:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 int D(int n){ 8 int sum=1; 9 for(int i=1;i<=n/2;i++){ 10 sum+=D(i); 11 } 12 return sum; 13 } 14 int main(){ 15 int n; 16 cin>>n; 17 cout<<D(n)<<endl; 18 return 0; 19 }?
轉載于:https://www.cnblogs.com/Kiven5197/p/5665023.html
總結
- 上一篇: flex工具学习二
- 下一篇: Tomcat工作原理