郑州大学算法设计与分析实验4

1

cpp 复制代码
#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;

const int N = 110;
int t, n;
int f[N][N], a[N][N];

void solve()
{
	cin >> n;
	rep(i,1,n)	rep(j,1,i)	cin >> a[i][j];
	rep(i,1,n)	rep(j,1,i)
	{
		f[i][j] = a[i][j];
		int t = 0;
		if(i-1>=1)	t = max(t, f[i-1][j]);
		if(j-1>=1 && i-1>=1)	t = max(t, f[i-1][j-1]);
		f[i][j] += t;
	}
	int ans = 0;
	rep(j,1,n)	ans = max(ans, f[n][j]);
	cout << ans << endl;
}

int main()
{
	IOS	
//	freopen("1.in", "r", stdin);
//	cin >> t;
//	while(t --)	
	solve();
	return 0;
}

2

cpp 复制代码
#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;


const int N = 1010;
int t, n, m;
char a[N], b[N];
int f[N][N];

void solve()
{
	cin >> (a+1);
	cin >> (b+1);
	n = strlen(a+1);
	m = strlen(b+1);
	rep(i,1,n)	rep(j,1,m)
	{
		f[i][j] = max(f[i-1][j], f[i][j-1]);
		if(a[i] == b[j])	f[i][j] = max(f[i][j], f[i-1][j-1] + 1);
	} 
	cout << f[n][m] << endl;
}

int main()
{
	IOS	
//	freopen("1.in", "r", stdin);
//	cin >> t;
//	while(t --)	
	solve();
	return 0;
}

3

cpp 复制代码
#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;

const int N = 110;
int t, n;
int a[N], f[N];

void solve()
{
	cin >> n;
	rep(i,1,n)	cin >> a[i];
	rep(i,1,n)
	{
		f[i] = 1;
		rep(j,1,i-1)
			if(a[j] <= a[i])	f[i] = max(f[i], f[j] + 1);
	}	
	int ans = 0;
	rep(i,1,n)	ans = max(ans, f[i]);
	cout << ans << endl;
}

int main()
{
	IOS	
//	freopen("1.in", "r", stdin);
//	cin >> t;
//	while(t --)	
	solve();
	return 0;
}

4

cpp 复制代码
#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f

using namespace std;
const int N = 110;
int t, n;
int a[N], s[N], f[N];

void solve()
{
	cin >> n;
	rep(i,1,n)	 cin >> a[i], s[i] = s[i-1] + a[i];
	int minn = INF;
	rep(i,1,n) 
	{
		f[i] = min(s[i], minn);
		minn = min(minn, f[i]);
	}
	int ans = 0;
	rep(i,1,n)	ans = max(ans, s[i] - f[i]);
	cout << max(0, ans) << endl;
}

int main()
{
	IOS	
//	freopen("1.in", "r", stdin);
//	cin >> t;
//	while(t --)	
	solve();
	return 0;
}

5

cpp 复制代码
#include <bits/stdc++.h> 
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f

using namespace std;
const int N = 110;
int t, n, m;
int a[N][N], s[N][N];

void solve()
{
	cin >> n >> m;
	rep(i,1,n)	rep(j,1,m) 	cin >> a[i][j];
	rep(i,1,n)	rep(j,1,m)	s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
	int ans = 0, x1, y1, x2, y2;
	rep(i,1,n)	rep(j,1,m)	rep(p,1,i)	rep(q,1,j)
	{
		int t = s[i][j] - s[i][q-1] - s[p-1][j] + s[p-1][q-1];
		if(t > ans)
		{
			ans = t;
			x1 = p; y1 = q;
			x2 = i; y2 = j;
		}
	}
	cout << ans << endl;
	cout << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << endl;
}

int main()
{
	IOS	
//	freopen("1.in", "r", stdin);
//	cin >> t;
//	while(t --)	
	solve();
	return 0;
}
相关推荐
埃菲尔铁塔_CV算法19 分钟前
深度学习神经网络创新点方向
人工智能·深度学习·神经网络
ChoSeitaku26 分钟前
链表循环及差集相关算法题|判断循环双链表是否对称|两循环单链表合并成循环链表|使双向循环链表有序|单循环链表改双向循环链表|两链表的差集(C)
c语言·算法·链表
娅娅梨28 分钟前
C++ 错题本--not found for architecture x86_64 问题
开发语言·c++
DdddJMs__13531 分钟前
C语言 | Leetcode C语言题解之第557题反转字符串中的单词III
c语言·leetcode·题解
兵哥工控32 分钟前
MFC工控项目实例二十九主对话框调用子对话框设定参数值
c++·mfc
Fuxiao___35 分钟前
不使用递归的决策树生成算法
算法
艾思科蓝-何老师【H8053】37 分钟前
【ACM出版】第四届信号处理与通信技术国际学术会议(SPCT 2024)
人工智能·信号处理·论文发表·香港中文大学
我爱工作&工作love我40 分钟前
1435:【例题3】曲线 一本通 代替三分
c++·算法
秀儿还能再秀1 小时前
机器学习——简单线性回归、逻辑回归
笔记·python·学习·机器学习
weixin_452600691 小时前
《青牛科技 GC6125:驱动芯片中的璀璨之星,点亮 IPcamera 和云台控制(替代 BU24025/ROHM)》
人工智能·科技·单片机·嵌入式硬件·新能源充电桩·智能充电枪