zoj 1483 划分类DP

还是看了little_w大神写的才知道怎么写,看完发现自己题意也理解错了,里面有个neighboring,意思就是你指定任务的时候指定的是原序列中连续的一段

然后就是怎么DP了,新学了个很好的dp模型 dp[i][j]表示前i个robot已经分担了j个任务是否可行,可行为1,不可行为0.所以对于某个当前的dp[i][j],只要找到一个合法的dp[i-1][w]存在,即可把当前值也设置为存在。这个模型就可以把当前robot包含了0个 1个 。。。m个都囊括进去了。想通了这个,其他没什么了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int n,m,k;
int s[510];
int dp[510][510];
int main()
{
    while (scanf("%d%d%d",&n,&m,&k)!=EOF)
    {
        for (int i=1;i<=m;i++){
            scanf("%d",&s[i]);
            s[i]+=s[i-1];
        }
        LL L,R;
        if (s[m]%n==0){
            L=s[m]/n-k;
            R=s[m]/n+k;
        }
        else{
            L=s[m]/n-k+1;
            R=s[m]/n+k;
        }
        if (L<0) L=0;
        memset(dp,0,sizeof dp);
        for (int i=0;i<=m;i++)dp[0][i]=1;
        for (int i=1;i<=n;i++){
            for (int j=0;j<=m;j++){
                for (int w=j;s[j]-s[w]<=R && w>=0;w--){
                    if (s[j]-s[w]<L) continue;
                    if (dp[i-1][w]) dp[i][j]=1;
                }
            }
        }
        if (dp[n][m]) puts("possible");
        else puts("impossible");
    }
    return 0;
}

  

时间: 2024-08-12 23:14:40

zoj 1483 划分类DP的相关文章

HDU 4826 (分类DP)

Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1368    Accepted Submission(s): 574 Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,

[ACM] ZOJ 3725 Painting Storages (DP计数+组合)

Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with e

ZOJ 3306 状压dp

转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds Memory Limit: 32768 KB In order to celebrate the 8th anniversary of ZOJ, watashi introduces a strange game to other ZJU ACM team members. The board of

Food Delivery ZOJ - 3469 (区间dp)

Food Delivery ZOJ - 3469 题意:快递员送外卖,n个客户,起始位置为x,速度为v,每个客户单位时间不满意度增加hi,问最少增加多少不满意度. 每一个客户可能是从左侧送到或者从右侧送到. 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define CLR(m,a) memset(m,a,sizeof(m)) 4 const int maxn=1010; 5 const int inf=0x3f3f3f3f; 6 i

zoj 3634 Bounty hunter(dp,没完全想清楚,需要回头再看_20151027)

M - Bounty hunter Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description Bounty hunter is a hero who always moves along cities to earn money by his power. One day he decides to N cities one by one At the

zoj 3471状态压缩DP

#include<stdio.h> #include<string.h> int max(int a,int b) { if(a>b) return a; return b; } int dp[100000],map[15][15],mark[15]; int main() { int i,j,n,m,k; while(scanf("%d",&n)!=EOF&&n) { for(i=1;i<=n;i++) for(j=1;j&

zoj 3367 Counterfeit Money(dp)

先搞定这题.ZOJ1985 Largest Rectangle in a Histogram 再做这题.先枚举第二个矩形对第一个矩形的偏移量(x,y),再进行2维DP,复杂度为O(n^2 *n^2),即O(n^4). #include <bits/stdc++.h> using namespace std; const int maxn=42; int n1,m1,n2,m2; char a[maxn][maxn]; char b[maxn][maxn]; int dp[maxn][maxn]

ZOJ 3822 Domination 概率DP

题意:在一个n*m的棋盘上放棋子,一个棋子可覆盖一行一列,若n行m列全被覆盖则停止放棋子,求棋子的期望 思路:期望DP, dp[i][j][k]表示放了i个棋子覆盖了j行k列 已知dp[0][0][0]=1,求dp[1~n*m][n][m] 四种情况: 1.再放一个棋子,行列都不增加 dp[i+1][j][k]+=dp[i][j][k]*(j*k-i)*1.0/(m*n-i); 2.只增加一行 dp[i+1][j+1][k]+=dp[i][j][k]*(n-j)*k*1.0/(m*n-i); 3

ZOJ 3329 【概率DP】

题意: 给你三个均匀k面筛子. 分别有k1 k2 k3个面,每个面朝上的概率是相等的. 如果第一个筛子出现a第二个筛子出现b第三个筛子出现c那么置零. 否则在当前和加上三个点数之和. 求当前和大于n需要的步数的期望. 思路: 一开始状态转移搞错了,手推公式交了WA,后来想了想状态转移的过程发现每个状态都跟0状态有关系,但是dp[0]不确定,但是幸运的是这是一个线性变换,所以状态转移的时候记录一下dp[0]的系数,最后移项输出就好了. dp[i]=dp[i+x]*(k1*k2*k3);(x=i+j