当前位置:网站首页>Data tower problem and deformation
Data tower problem and deformation
2022-07-20 08:26:00 【C0re in the lonely age】
Catalog
The theory exists , Practice begins !
Foundation tower ( Number triangle problem )
Love is worth years. Love is worth years .
Preface
About several towers dp
Topic introduction
sample input :
6
5 1
4 1
6 1
7 2
7 2
8 3
0
sample output :
4
Before starting, you can write it yourself to see if you can write it yourself ~ Pay attention to the output format !
introduce :
I want to understand that it is a number tower pushed forward from the end ?? The final output dp[0][5] The value of is not good ? Okay , Is not dynamic planning :》
The theory exists , Practice begins !
Foundation tower ( Number triangle problem )
Topic introduction :
sample input :
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
sample output :
30
#include <stdio.h>
int max (int a,int b);
int max (int a,int b)
{
if(a>b) return a;
else return b;
}
int main()
{
int n;
scanf("%d",&n);
int max_sum[n][n];
int d[n][n];;
int i,j;
for (i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
scanf("%d",&d[i][j]);
}
}
for (j=0;j<n;j++)
{
max_sum[n-1][j]=d[n-1][j];
}
for (i=n-2;i>=0;i--)
for (j=0;j<i+1;j++)
{
max_sum[i][j]=d[i][j]+max(max_sum[i+1][j],max_sum[i+1][j+1]);
}
printf("%d",max_sum[0][0]);
}
Similar to this topic
#include <stdio.h>
#include <string.h>
int max (int a,int b,int c)
{
int max=a;
if(b>max)max=b;
if(c>max)max=c;
return max;
}
int max_t(int a,int b)
{
if(a>b)return a;
else return b;
}
int dp[100010][12];
int a[100010][12];// Line represents time , The list shows the pie over there .
int main()
{
int n;
int x,t;
int i,j;
int maxt=0;
while(scanf("%d",&n)!=EOF)
{
memset(dp,0,sizeof(dp));
memset(a,0,sizeof(a));
if(n==0)break;
for (i=0;i<n;i++)
{
scanf("%d%d",&x,&t);
a[t][x]++;
if(t>maxt)maxt=t;
}
for (j=0;j<=10;j++)
{
dp[maxt][j]=a[maxt][j];
}
for (i=maxt-1;i>=0;i--)
{
for (j=0;j<=10;j++)
{
if(j==0) dp[i][j]=max_t(dp[i+1][j],dp[i+1][j+1])+a[i][j];
else
dp[i][j]=max(dp[i+1][j],dp[i+1][j+1],dp[i+1][j-1])+a[i][j];
}
}
printf("%d\n",dp[0][5]);
}
}
Precautions for this topic :
1. Reset the array after each group of input memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); The operation of .
2. Want to consider j==0 The situation may lead to errors
3. Don't consider the right endpoint because we set it all to 0 了 .
4. Stack storage will report an error -1073741571 (0xC00000FD) That is, the array is too large , You can use global variables or structure definitions to solve
Love is worth years.
Love is worth years .
边栏推荐
猜你喜欢
pytorch 使用免费gpu测试训练(aistudio)yolov4为例
YOLOv5实现火焰和烟雾检测
SSM notes
牛客剑指offer 剪绳子
递归回溯—走迷宫
[yolov5 realizes mobile phone detection]
Jenkins linked flybook pushes the test report notification message in the form of signature verification
MySQL ten million level sub table optimization
Idea SVN trunk merge branch version missing ranges exception error:svn: e195016
巧解杨氏矩阵
随机推荐
steam文件夹移动后游戏需要重新安装怎么办
Partition of integers
基于STM32F030的ADC功能实现
仿联系人的排序
MySQL ten million level sub table optimization
Common network vendor MIB library files
Yolov5 apple banana detection
There is a problem that the picture cannot be found after the jar package is printed on the swing form
数据的表示和运算
Jenkins 联动 飞书 以签名校验方式 推送测试报告通知消息
指针和数组的相关练习题
C语言结构体知识分享
八皇后问题,秒懂递归回溯(有图详解|c语言)
华录杯-江苏违法广告检测-冠军总结
STM32-使用定时器做延时函数时遇到的坑
指针运算练习题及字符串函数
[Day.2]约瑟夫环问题,如何用数组代替循环链表(详解)
学生成绩管理系统(c语言)
pytorch 实现数据增强分类 albumentations的使用
Servlet入门