Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大牛们讲的好多知识点,滚动数组什么的……一个不懂,贡献一个超简单易懂代码235MS过,嘿嘿……#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator