NOIP T4多出的20分
查看原帖
NOIP T4多出的20分
907536
one_zero_two_zero楼主2023/11/18 20:38

在今年 NOIPNOIP 的 T4T4 中,我写出了如下玄学代码

#include<bits/stdc++.h>
using namespace std;

struct node{
	int yi,vi;
};

int c,t;
int n,m,k,d;
int x,y,v;
long long dp[2][100005],maxn[100005];
vector<node> a[100005];

int main(){
	freopen("run.in","r",stdin);
	freopen("run.out","w",stdout);
	
	scanf("%d %d",&c,&t);
	while(t --){
		scanf("%d %d %d %d",&n,&m,&k,&d);
		for(int i = 0;i <= 100000;i ++) a[i].clear();
		for(int i = 0;i < 2;i ++){
			for(int j = 0;j <= 100000;j ++){
				maxn[j] = dp[i][j] = 0;
			}
		}
		while(m --){
			scanf("%d %d %d",&x,&y,&v);
			a[x].push_back({y,v});
		}
		for(int i = 1;i <= n;i ++){
			dp[i & 1][0] = maxn[i - 1];
			maxn[i] = dp[i & 1][0];
			for(int j = 1;j <= k;j ++){
				long long cur = dp[(i - 1) & 1][j - 1] - d;
				int pos = a[i].size();
				for(int g = 0;g < pos;g ++){
					if(a[i][g].yi <= j) cur += a[i][g].vi;
				}
				dp[i & 1][j] = cur;
				maxn[i] = max(maxn[i],cur);
			}
		}
		printf("%lld\n",maxn[n]);
	}

	return 0;
}

我觉得他的时间复杂度是 O(n2m)O(n^{2}m) ,原则上应该能拿到 16pts16pts 但是测出来是 36pts36pts

是我代码的时间复杂度没这么劣还是纯粹是数据水

2023/11/18 20:38
加载中...