Jisoo

显然的转移,但是会是\(O(n^3)\)的,这很不好

但是可以意识到从不是同一颗树转移的时候,无需在意到底是那颗而只在意最大值

并且不会影响从自己转移

那就记录一下最大值

#include<iostream> 
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
//#define int long long
using namespace std;
int f[2005][2005];
int pre[2005];
template <class T>
T read(T &now){
	 now=0;
	T f=0;
	char c=getchar(); 
	while(!isdigit(c)){
		f=(c=='-');
		c=getchar();
	}
	while(isdigit(c)){
		now=(now<<1)+(now<<3)+c-'0';
		c=getchar();
	}
	if(f) now=-now;
	return now;
}
int x;
int y;
int n,h,de;
int ex[2005][2005];
int main(){
	read(n);read(h);read(de);
	for(int i=1;i<=n;++i){
		read(x);
		for(int j=1;j<=x;++j){
			read(y);
			ex[i][y]++;
		}
	}
	for(int i=h;i>=0;--i){
		for(int j=1;j<=n;++j){
			f[i][j]=f[i+1][j]+ex[j][i];
			if(i+de<=h){
				f[i][j]=max(f[i][j],pre[i+de]+ex[j][i]); 
			}
			pre[i]=max(pre[i],f[i][j]);
		}
	//	cout<<pre[i]<<endl;
	}
	cout<<pre[0];
	return 0;
}

相关文章:

  • 2022-12-23
  • 2021-09-19
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-23
  • 2022-12-23
猜你喜欢
  • 2022-02-23
  • 2022-02-28
  • 2022-12-23
  • 2022-02-06
  • 2022-02-27
  • 2021-08-25
相关资源
相似解决方案