这个题目容易让人误以为是贪心就可以解决了,但是细想一下很容易举出反例。

dp[i][j]表示解决了i个问题,最后一个月解决的问题数目。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=3e2+9;
int a[maxn],b[maxn];
int suma[maxn],sumb[maxn];
int dp[maxn][maxn];
int main()
{
// freopen("in.txt","r",stdin);
int m,p;
while(scanf("%d %d",&m,&p)!=EOF)
{
suma[0]=sumb[0]=0;
for(int i=1;i<=p;i++)
{
scanf("%d %d",&a[i],&b[i]);
suma[i]=suma[i-1]+a[i];
sumb[i]=sumb[i-1]+b[i];
}
memset(dp,50,sizeof(dp));
dp[0][0]=0;
for(int i=0;i<=p;i++)
for(int j=i;j>=0;j--)
{
for(int k=i;k<=p;k++)
{
if(suma[k]-suma[i]+sumb[i]-sumb[i-j]>m)
break;
if(sumb[k]-sumb[i]>m)
break;
dp[k][k-i]=min(dp[k][k-i],dp[i][j]+1);
}
}
printf("%d\n",dp[p][0]+1);
}
return 0;
}

poj 3265 Problem Solving dp的更多相关文章

  1. bzoj 1700 Problem Solving 解题 dp

    [Usaco2007 Jan]Problem Solving 解题 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 492  Solved: 288[Sub ...

  2. POJ 1260 Pearls 简单dp

    1.POJ 1260 2.链接:http://poj.org/problem?id=1260 3.总结:不太懂dp,看了题解 http://www.cnblogs.com/lyy289065406/a ...

  3. poj 1463 Strategic game DP

    题目地址:http://poj.org/problem?id=1463 题目: Strategic game Time Limit: 2000MS   Memory Limit: 10000K Tot ...

  4. POJ 1947 (树形DP+背包)

    题目链接: http://poj.org/problem?id=1947 题目大意:树中各点都由一条边连接.问要弄出个含有m个点的(子)树,至少需要截去多少条边. 解题思路: 设dp[i][j]为i总 ...

  5. [POJ 1155] TELE (树形dp)

    题目链接:http://poj.org/problem?id=1155 题目大意:电视台要广播电视节目,要经过中转机构,到观众.从电视台到中转商到观众是一个树形结构,经过一条边需要支付成本.现在给你每 ...

  6. poj -2229 Sumsets (dp)

    http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...

  7. poj 1651 http://poj.org/problem?id=1651

      http://poj.org/problem?id=1651Multiplication Puzzle   Time Limit: 1000MS   Memory Limit: 65536K To ...

  8. poj-3056 http://poj.org/problem?id=3056

    http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS   Memory Limit: 65536K Tot ...

  9. poj 3046 Ant Counting (DP多重背包变形)

    题目:http://poj.org/problem?id=3046 思路: dp [i] [j] :=前i种 构成个数为j的方法数. #include <cstdio> #include ...

随机推荐

  1. 基于visual Studio2013解决C语言竞赛题之1054抽牌游戏

       题目 解决代码及点评 /************************************************************************/ /* 54 ...

  2. windows和linux套接字中的select机制浅析

    先来谈谈为什么会出现select函数,也就是select是解决什么问题的? 平常使用的recv函数时阻塞的,也就是如果没有数据可读,recv就会一直阻塞在那里,这是如果有另外一个连接过来,就得一直等待 ...

  3. CodeForces 370C. Mittens

    C. Mittens time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  4. [LeetCode] Print All Combinations of a Number as a Sum of Candidate Numbers

    题目连接:http://leetcode.com/2010/09/print-all-combinations-of-number-as-sum.html 题目分析: 由于这里说明了输入是升序的,当然 ...

  5. 使用Iterator遍历Sheet(POI)验证及解释结果有序性

    test.xlsx: Code: package poi; import static org.junit.Assert.*; import java.io.IOException; import j ...

  6. 使用Understand获取某个函数(方法)的静态度量指标

    在之前的一篇日志中,我简单总结了调用Understand的Perl API的方法,这里再简单总结一些经验: 在SciTools\doc\manuals\pdf目录下的understand_api.pd ...

  7. md5增加指定的加密规则,进行加密

    import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.securit ...

  8. Android 系统搜索框(有浏览记录)

    实现Android 系统搜索框(有浏览记录),先看下效果: 一.配置搜索描述文件  要在res中的xml文件加创建sreachable.xml,内容如下: <?xml version=" ...

  9. 解决Myeclipse在port占用,导致tomcat无法启动。(Linux)

    本文来源于:http://blog.csdn.net/svitter 引文:http://www.2cto.com/os/201305/209285.html { ubuntu查看占用某port的程序 ...

  10. 可编辑的表格:jQuery+PHP实现实时编辑表格字段内容

    在本例中,我们会通过jQuery实现单击将一个文本信息变为可编辑的表单,你可以对文本内容进行编辑,然后点击“确定”按钮,新的内容将发送到后台PHP程序处理,并保存到数据库:当点击“取消”按钮,则页面恢 ...