
- #include
- using namespace std;
- //从下向上得到最优值
- void dtower(int a[][100],int s[][100],int n)
- {
- for(int i=n; i>=1; i--)
- {
- for(int j=1; j<=i; j++)
- {
- if(i==n)
- s[i][j]=a[i][j];
- else
- {
- int t=s[i+1][j];
- if(t
1][j+1]) - t=s[i+1][j+1];
- s[i][j]=a[i][j]+t;
- }
-
- }
- }
- }
- void Traceback(int a[][100],int s[][100],int n,int i,int j)
- {
- if(i==n)
- cout<" "<
- else
- {
- cout<" "<
- if(s[i][j]==a[i][j]+s[i+1][j])
- Traceback(a,s,n,i+1,j);
- else
- Traceback(a,s,n,i+1,j+1);
- }
- }
- int main()
- {
- int n;cin>>n;
- int a[100][100]={0},s[100][100]={0};
- for(int i=1;i<=n;i++)
- for(int j=1;j<=i;j++)
- cin>>a[i][j];
-
- dtower(a,s,n);
- cout<<"s[i][j]:"<
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=i;j++)
- cout<
" "; - cout<
- }
-
- Traceback(a,s,n,1,1);
- return 0;
- }
5
30
23 21
20 13 10
7 12 10 22
4 5 2 6 5

-
相关阅读:
代码覆盖率统计Super-jacoco在公司级容器化项目中的具体应用方案
prometheus告警流程及相关时间参数说明
2022 CCPC 桂林 (22-10-30) B
手敲Mybatis-SQL执行器
跨域与JSONP
实现虚拟机下“ Linux与Windows 共享文件夹 ”(附加VMware Tools的安装)
JavaSE——数组习题
为什么在Kubernetes上运行虚拟机?
基于Docker搭建Redis集群并进行扩容、缩容教程
玩转ChatGPT:ARIMA模型定制GPT-1.0
-
原文地址:https://blog.csdn.net/qq_74256533/article/details/139448892