Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

G++ 2612ms

Posted by ACAccepted at 2019-03-23 09:58:56 on Problem 1742 and last updated at 2019-03-23 10:00:00
#include <cstdio>
#include <cstring>
using namespace std;

int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
	return x*f;
}

template <typename T>
void print(T x)
{
	if (x<0)x=-x,putchar('-');
	if (x>9)print(x/10);
	putchar(x%10+48);
}

template <typename T>
void print(T x,char c)
{
	print(x);
	putchar(c);
}

const int MAXN=101;
const int MAXM=100010;
int n,m;
int a[MAXN],num[MAXN];
bool f[MAXM];

int main()
{
	while (true)
	{
		n=read();m=read();
		if (n==0&&m==0)break;
		for (int i=1;i<=m;i++)f[i]=false;
		for (int i=1;i<=n;i++)a[i]=read();
		for (int i=1;i<=n;i++)num[i]=read();
		int rest;f[0]=true;
		for (int i=1;i<=n;i++)
		{
			rest=num[i];
			for (int k=1;rest-k>=0;rest-=k,k*=2)
				for (int j=m;j>=a[i]*k;j--)
					f[j]=f[j]|f[j-a[i]*k];
			if (rest)
			{
				for (int j=m;j>=a[i]*rest;j--)
					f[j]=f[j]|f[j-a[i]*rest];
			}
		}
		int ans=0;
		for (int i=1;i<=m;i++)
			if (f[i])ans++;
		print(ans,'\n');
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator