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

大牛们讲的好多知识点,滚动数组什么的……一个不懂,贡献一个超简单易懂代码235MS过,嘿嘿……

Posted by leiqunlong at 2010-08-20 11:21:02 on Problem 1745
#include<stdio.h>
#include<iostream>
using namespace std;
bool dp[10001][101];
long num[10001];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		num[i]=a%k;
	}
	dp[0][0]=true;
 for(int i=1;i<=n;i++)
 {
	 for(int j=k-1;j>=0;j--)
		 if(dp[i-1][j])
		 {
			 dp[i][(j+num[i])%k]=1;
			 dp[i][(k+j-num[i])%k]=1;
		 }
 }
 if(dp[n][0])
	 printf("Divisible\n");
 else
	 printf("Not divisible\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