POJ 1745DP

简介:

题解:看了题觉得没什么思路 觉得如果一步一步推肯定超空间了 然后我看了黄学长的博客 啊 用两个数组来回推就行了 太巧妙了 

太弱了我 哎 还是做题不够 学长真是猛。。。

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define get(x) ((x)<0?(-(x))%k:(x)%k)
bool dp[2][105];
int yl[10005];
int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        for(int i=0; i<n; i++)
            scanf("%d",&yl[i]);
        for(int i=0; i<k; i++)
            dp[0][i]=0;
        dp[0][get(yl[0])]=1;
        int g1=1,g2=0;
        for(int i=1; i<n; i++)
        {
            g1=!g1,g2=!g2;
            for(int j=0; j<k; j++)
                dp[g2][j]=0;
            for(int j=0; j<k; j++)
                if(dp[g1][j])
                    dp[g2][get(j+yl[i])]=dp[g2][get(j-yl[i])]=1;
        }
        if(dp[g2][0])
            puts("Divisible");
        else
            puts("Not divisible");
    }
    return 0;
}


目录
相关文章
|
存储
POJ 1936 All in All
POJ 1936 All in All
63 0
POJ 1067 取石子游戏
取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 40917   Accepted: 13826 Description 有两堆石子,数量任意,可以不同。
1086 0
|
C语言
poj 2503 查字典
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language.
837 0
|
算法 数据建模 机器学习/深度学习
poj-1006-Biorhythms
Description 人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。
587 0
|
人工智能
POJ 1936 All in All
Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way.
756 0