萌新50分TLE求助!
查看原帖
萌新50分TLE求助!
158878
B1ade_楼主2020/5/31 15:48
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int dp[500005];
bool ok[500005];
int mon[205],mc[205],w[500005];
int main()
{
	int n,m;cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>mon[i]>>mc[i];
	int maxx=-1;
	for (int i=1;i<=m;++i)
	{
		cin>>w[i];
		maxx=max(maxx,w[i]);
	}
	memset(ok,0,sizeof(ok));
	ok[0]=1;
	for (int i=1;i<=m;++i)
	{
		memset(dp,0,sizeof(dp));
		for (int j=mon[i];j<=maxx;++j)
		{
			if(!ok[j]&&ok[j-mon[i]]==1&&dp[j-mon[i]]<mc[i])
			{
				ok[j]=1;
				dp[j]=dp[j-mon[i]]+1;
			}
		}
	}
	for (int i=1;i<=m;++i)
		if (ok[w[i]])
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	return 0;
}
2020/5/31 15:48
加载中...