记忆化搜索40pts,WA了后三个点求助
查看原帖
记忆化搜索40pts,WA了后三个点求助
1032994
jyxnb楼主2023/10/17 20:40
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cctype>
#include <queue>
#include <deque>
#include <ctime>
#include <cstring>
#include <string>
#define _e putchar (' ')
#define _v putchar ('\n')
#define ll long long
#define INF 999999999999999999ll
#define INE -999999999999999999ll
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;
inline int lowbit (int x) {
	return x&(-x);
}
inline int mx(int x,int y) {
	return x>y?x:y;
}
inline int mn(int x,int y) {
	return x<y?x:y;
}
inline void rd(int &x) {
	int s=0,w=1;
	char ch=getchar ();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar ();}
	while(ch>='0'&&ch<='9') {s=(s<<1)+(s<<3)+(ch^48); ch=getchar ();}
	x=s*w;
}
inline void wr(int x) {
	if(x<0) x=-x,putchar (45);
	if(x<10) {
		putchar (x+48);
		return ;
	}
	wr(x/10);
	putchar (x%10+48);
}
inline int ab (int x) {
	if(x<0) return -x;
	return x;
}
inline void swap (int &x,int &y) {
	x^=y^=x^=y;
}
const int N=100005;
int n,a[N],mem[N];
inline int dfs (int num) {
	if (mem[num]) return mem[num];
	if (num==n+1) return mem[num]=0;
	int maxn=-1e9;
	for (int i=1;i<num;i++) {
		if (a[num]>a[i]) {
			maxn=mx(maxn,dfs (i)+1);
		}
	}
	return mem[num]=maxn;
}
int main () {
	rd(n);
	mem[1]=1;
	for (int i=1;i<=n;i++) rd(a[i]);
	int maxx=-(1e9);
	for (int i=1;i<=n;i++) maxx=mx(maxx,dfs(i));
	wr(maxx),_v;
	return 0;
}



2023/10/17 20:40
加载中...