⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1036gangsters.cpp

📁 算法编程题,北京大学OnlineJudge 1036Gangsters
💻 CPP
字号:
#include<stdio.h>  
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<vector>
#include<set>
#include<map>
using namespace std;


//最长上升子序列问题
//O(N^2)

struct node{
	int t,p,s;
} a[101];


int N,K,T;
int f[101];
int s[101];

bool cmp(const node& lhs,const node& rhs){
	return lhs.t<rhs.t;
}

bool Input(){
	if(scanf("%d%d%d",&N,&K,&T)==EOF){
		return 0;
	}
	int i;
	for(i=1;i<=N;i++){
		scanf("%d",&a[i].t);
	}
	for(i=1;i<=N;i++){
		scanf("%d",&a[i].p);
	}
	for(i=1;i<=N;i++){
		scanf("%d",&a[i].s);
	}
	return 1;
}

void Solve(){
	int i,j,k;
	sort(a+1,a+N+1,cmp);
	s[0]=0,f[0]=0;
	for(i=1;i<=N;i++){
		f[i]=0;
		for(j=0;j<i;j++){
			if((abs(a[i].s-s[j])<=a[i].t-a[j].t)&&(f[j]+a[i].p>f[i])){
				f[i]=f[j]+a[i].p;
				s[i]=a[i].s;
			}
		}
	}
	int ret=0;
	for(i=1;i<=N;i++){
		if(f[i]>ret){
			ret=f[i];
		}
	}
	printf("%d\n",ret);
	return;
}

int main()
{
	//freopen("in.txt","r",stdin);
	while(Input()){
		Solve();
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -