2
6
184756
252
<span style="font-size:24px;"><span style="color: rgb(51, 51, 51);">第一种做法是递归 把边界置为 1, </span><span style="color:#ff0000;">然后中间每个格子等于上一步和左一部的走法之和</span></span>
<span style="font-family:Menlo, Monaco, Consolas, Courier New, monospace;color:#333333;"><span style="font-size: 18px; line-height: 25.7143px; white-space: pre-wrap;">#include <iostream>
using namespace std;
int main()
{
long long a[21][21];
for(int i=0;i<21;i++)
{
a[i][0]=1;
a[0][i]=1;
}
for(int i=1;i<21;i++)
{
for(int j=1;j<21;j++)
a[i][j]=a[i-1][j]+a[i][j-1];
}
int n;
while(cin>>n&&n)
{
cout<<a[n][n]<<endl;
}
return 0;
}</span></span>
<span style="font-family:Menlo, Monaco, Consolas, Courier New, monospace;color:#333333;"><span style="font-size: 18px; line-height: 25.7143px; white-space: pre-wrap;">
</span></span>
<span style="font-family:Menlo, Monaco, Consolas, Courier New, monospace;color:#333333;"><span style="font-size: 18px; line-height: 25.7143px; white-space: pre-wrap;">
</span></span>
<span style="font-family:Menlo, Monaco, Consolas, Courier New, monospace;color:#333333;"><span style="font-size: 18px; line-height: 25.7143px; white-space: pre-wrap;">递归写法 倒着推</span></span>
<xmp class="prettyprint prettyprinted" style="box-sizing: border-box; word-wrap: break-word !important;"><span style="font-size:24px;color:#333333;"><span style="white-space: pre-wrap;">#include <iostream>
#include<string.h>
using namespace std;
long long a[21][21];
long long digui(int x,int y)
{
if (a[x][y]!=0) return a[x][y]; //被算过
int result;
if (x==0||y==0)
result=1;
else
result=digui(x-1,y)+digui(x,y-1);
a[x][y]=result; //每个格子只算一次~~
return result;
}
int main()
{
memset(a,0,sizeof(a));
int n;
while(cin>>n&&n)
{
cout<<digui(n,n)<<endl; //从最后往上推
}
return 0;
}</span></span>
<div class="panel-heading" style="box-sizing: border-box; padding: 10px 15px; border-bottom-width: 1px; border-bottom-style: solid; border-color: rgb(51, 122, 183); border-top-left-radius: 3px; border-top-right-radius: 3px; color: rgb(255, 255, 255); font-family: 'Helvetica Neue', Helvetica, Arial, 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', 'Microsoft YaHei UI', 'Microsoft YaHei', sans-serif; font-size: 14px; line-height: 24.5px; white-space: normal; background-color: rgb(51, 122, 183);"><h3 class="text-center" id="contestShowProblem-title" style="box-sizing: border-box; font-family: inherit; font-weight: 500; line-height: 1.1; color: inherit; margin-top: 20px; margin-bottom: 10px; font-size: 24px; text-align: center;">步步惊心</h3></div><div class="panel-body" style="box-sizing: border-box; padding: 15px; color: rgb(80, 80, 80); font-family: 'Helvetica Neue', Helvetica, Arial, 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', 'Microsoft YaHei UI', 'Microsoft YaHei', sans-serif; font-size: 14px; line-height: 24.5px; white-space: normal;"><div class="row text-center" style="box-sizing: border-box; text-align: center; margin-right: -15px; margin-left: -15px;"><div class="col-sm-4" style="box-sizing: border-box; position: relative; min-height: 1px; padding-right: 15px; padding-left: 15px; float: left; width: 287.234px;"><h4 style="box-sizing: border-box; font-family: inherit; font-weight: 500; line-height: 1.1; color: inherit; margin-top: 10px; margin-bottom: 10px; font-size: 18px;">Problem:<span id="contestShowProblem-problem" style="box-sizing: border-box;">D</span></h4></div><div class="col-sm-4" style="box-sizing: border-box; position: relative; min-height: 1px; padding-right: 15px; padding-left: 15px; float: left; width: 287.234px;"><h4 style="box-sizing: border-box; font-family: inherit; font-weight: 500; line-height: 1.1; color: inherit; margin-top: 10px; margin-bottom: 10px; font-size: 18px;">Time Limit:<span id="contestShowProblem-timeLimit" style="box-sizing: border-box;">1000</span>ms</h4></div><div class="col-sm-4" style="box-sizing: border-box; position: relative; min-height: 1px; padding-right: 15px; padding-left: 15px; float: left; width: 287.234px;"><h4 style="box-sizing: border-box; font-family: inherit; font-weight: 500; line-height: 1.1; color: inherit; margin-top: 10px; margin-bottom: 10px; font-size: 18px;">Memory Limit:<span id="contestShowProblem-memoryLimit" style="box-sizing: border-box;">65536</span>K</h4></div></div></div><div class="panel panel-info" style="box-sizing: border-box; margin-bottom: 20px; border: 1px solid rgb(188, 232, 241); border-radius: 4px; box-shadow: rgba(0, 0, 0, 0.0470588) 0px 1px 1px; color: rgb(80, 80, 80); font-family: 'Helvetica Neue', Helvetica, Arial, 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'WenQuanYi Micro Hei', 'Microsoft YaHei UI', 'Microsoft YaHei', sans-serif; font-size: 14px; line-height: 24.5px; white-space: normal;"><div class="panel-heading" style="box-sizing: border-box; padding: 10px 15px; border-bottom-width: 1px; border-bottom-style: solid; border-color: rgb(188, 232, 241); border-top-left-radius: 3px; border-top-right-radius: 3px; color: rgb(49, 112, 143); background-color: rgb(217, 237, 247);"><h3 class="panel-title" style="box-sizing: border-box; font-family: inherit; font-weight: 500; line-height: 1.1; color: inherit; margin-top: 0px; margin-bottom: 0px; font-size: 16px;">Description</h3></div><div class="panel-body" style="box-sizing: border-box; padding: 15px;"><pre class="pre-large-font" id="contestShowProblem-description" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 15px; padding: 0px 10px; margin-top: 0px; margin-bottom: 0px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: normal; border: 0px; border-radius: 4px; word-wrap: break-word !important; white-space: pre-wrap !important; background-color: inherit;"><xmp style="box-sizing: border-box; font-family: inherit; font-size: 18px; white-space: pre-wrap !important; word-wrap: break-word !important;">马尔泰·若曦是康熙年间镇西大将军马尔泰的小女儿,自幼失母,却深得父亲姐姐宠爱,性格活泼任性。张晓,本是21世纪一都市白领,聪慧谨慎,玲珑剔透。因车祸而灵魂穿越到若曦身上,自此开始了步步惊心的宫庭之旅,并身不由己卷进了九龙夺嫡的风波。在这里,若曦与大清未来的皇帝----雍正皇帝新觉罗·胤禛相遇,并上演了一场爱恨情仇中的生死挣扎。权利与亲情、与爱情;欲望和名利下上演一场场惊天动地,凄凉婉转的、曲折的惊心动魄的历史片段。最后在无奈和挣扎中香消玉损,只留下雍正痛苦的坚持和对大清的责任。
若曦刚来到北京皇宫时,就对复杂的皇宫所迷惑---屋子太多了。皇宫的屋子是m行n列的方格,进到理想的屋子里会得到奖赏(银子),走到禁闭的屋子要扣月厘(银子),难啊。若曦从左下角(1,1)位置,走到右上角(m,n)位置,通过最短的距离能获得的最多银子是多少啊?
(1,1)是左下角的屋子的坐标。