hdu 2151
就是一个dp,数组内存的步数,
数组没清空,wa了一次
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; int step[110][110]; int main() { int N,P,M,T; while(scanf("%d%d%d%d",&N,&P,&M,&T)!=EOF){ memset(step,0,sizeof(step)); step[0][P]=1; for(int i=1;i<=M;i++){ for(int j=1;j<=N;j++){ if(step[i-1][j+1]!=0&&j+1<=N) step[i][j]+=step[i-1][j+1]; if(step[i-1][j-1]!=0&&j-1>=1) step[i][j]+=step[i-1][j-1]; } } // for(int i=1;i<=M;i++){ // for(int j=1;j<=N;j++){ // printf("%d ",step[i][j]); // } // printf("\n"); // } printf("%d\n",step[M][T]); } return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步