2013-09-07

poj 3176

Cow Bowling

Description

The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this: 

          7



        3   8



      8   1   0



    2   7   4   4



  4   5   2   6   5
Then the other cows traverse the triangle starting from its tip and moving "down" to one of the two diagonally adjacent cows until the "bottom" row is reached. The cow's score is the sum of the numbers of the cows visited along the way. The cow with the highest score wins that frame. 

Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.

Input

Line 1: A single integer, N 

Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.

Output

Line 1: The largest sum achievable using the traversal rules

Sample Input

5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5

Sample Output

30

Hint

Explanation of the sample: 

          7

         *

        3   8

       *

      8   1   0

       *

    2   7   4   4

       *

  4   5   2   6   5
The highest score is achievable by traversing the cows as shown above.


代码:
#include <stdio.h>
#include <algorithm>
using namespace std;

int a[360][360],d[360][360];

int main()
{
    int n,i,j;
    scanf("%d",&n);

    for(i=0;i<n;i++)
      for(j=0;j<=i;j++)
        scanf("%d",&a[i][j]);

        d[0][0]=a[0][0];

        for(i=1;i<n;i++)
        {
            d[i][0]=d[i-1][0]+a[i][0];
            d[i][i]=d[i-1][i-1]+a[i][i];

            for(j=1;j<i;j++)
            {
                d[i][j]=max(d[i-1][j-1],d[i-1][j]);
                  d[i][j]+=a[i][j];
            }

        }

        int c=0;
      for(i=0;i<n;i++)
      c=max(c,d[n-1][i]);

      printf("%d\n",c);
}








poj   2385


Apple Catching

Description

It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall. However, she must catch them in the air since the apples bruise when they hit the ground (and no one wants to eat bruised apples). Bessie is a quick eater, so an apple she does catch is eaten in just a few seconds. 

Each minute, one of the two apple trees drops an apple. Bessie, having much practice, can catch an apple if she is standing under a tree from which one falls. While Bessie can walk between the two trees quickly (in much less than a minute), she can stand under only one tree at any time. Moreover, cows do not get a lot of exercise, so she is not willing to walk back and forth between the trees endlessly (and thus misses some apples). 

Apples fall (one each minute) for T (1 <= T <= 1,000) minutes. Bessie is willing to walk back and forth at most W (1 <= W <= 30) times. Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree 1.

Input

* Line 1: Two space separated integers: T and W 

* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.

Output

* Line 1: The maximum number of apples Bessie can catch without walking more than W times.

Sample Input

7 2
2
1
1
2
2
1
1

Sample Output

6

Hint

INPUT DETAILS: 

Seven apples fall - one from tree 2, then two in a row from tree 1, then two in a row from tree 2, then two in a row from tree 1. Bessie is willing to walk from one tree to the other twice. 

OUTPUT DETAILS: 

Bessie can catch six apples by staying under tree 1 until the first two have dropped, then moving to tree 2 for the next two, then returning back to tree 1 for the final two.


代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int dp[1005][35];
int a[1005];

int main()
{
    int i,j;
    int t,w;

    scanf("%d%d",&t,&w);

    for(i=1;i<=t;i++)
        scanf("%d",&a[i]);

        memset(dp,0,sizeof(dp));

     if(a[1]==1)
       {
           dp[1][0]=1;
            dp[1][1]=0;
       }
    else { dp[1][0]=0;dp[1][1]=1;}
    for(i=2;i<=t;i++)
      for(j=0;j<=w;j++)
    {
       if(i-1>=j)
       {
          if(j==0)
            dp[i][j]=dp[i-1][j];
          else
           dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]);
          if(j%2+1==a[i])
             dp[i][j]++;
       }


    }

    int c=0;
    for(i=0;i<=w;i++)
        c=max(dp[t][i],c);

    printf("%d\n",c);
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
我的电脑显卡是NVIDIA CUDA 11.6.114 driver,win10,64位的,在安装Anaconda时,有如下几个版本:Anaconda-1.4.0-Windows-x86_64.exe 241.4 MiB 2013-07-04 17:58 Anaconda-1.5.0-Linux-x86.sh 238.8 MiB 2013-07-04 18:10 Anaconda-1.5.0-Linux-x86_64.sh 306.7 MiB 2013-07-04 18:22 Anaconda-1.5.0-MacOSX-x86_64.sh 166.2 MiB 2013-07-04 18:37 Anaconda-1.5.0-Windows-x86.exe 236.0 MiB 2013-07-04 18:45 Anaconda-1.5.0-Windows-x86_64.exe 280.4 MiB 2013-07-04 18:57 Anaconda-1.5.1-MacOSX-x86_64.sh 166.2 MiB 2013-07-04 19:11 Anaconda-1.6.0-Linux-x86.sh 241.6 MiB 2013-07-04 19:19 Anaconda-1.6.0-Linux-x86_64.sh 309.5 MiB 2013-07-04 19:32 Anaconda-1.6.0-MacOSX-x86_64.sh 169.0 MiB 2013-07-04 19:47 Anaconda-1.6.0-Windows-x86.exe 244.9 MiB 2013-07-04 19:56 Anaconda-1.6.0-Windows-x86_64.exe 290.4 MiB 2013-07-04 20:09 Anaconda-1.6.1-Linux-x86.sh 247.1 MiB 2013-07-05 08:34 Anaconda-1.6.1-Linux-x86_64.sh 317.6 MiB 2013-07-05 09:20 Anaconda-1.6.1-MacOSX-x86_64.pkg 197.3 MiB 2013-07-05 10:05 Anaconda-1.6.1-MacOSX-x86_64.sh 170.0 MiB 2013-07-05 12:20 Anaconda-1.6.1-Windows-x86.exe 244.4 MiB 2013-07-05 12:29 Anaconda-1.6.1-Windows-x86_64.exe 289.9 MiB 2013-07-05 12:49 Anaconda-1.6.2-Windows-x86.exe 244.4 MiB 2013-07-10 06:19 Anaconda-1.6.2-Windows-x86_64.exe 289.9 MiB 2013-07-10 07:04 Anaconda-1.7.0-Linux-x86.sh 381.0 MiB 2013-09-20 01:04 Anaconda-1.7.0-Linux-x86_64.sh 452.6 MiB 2013-09-20 02:49 Anaconda-1.7.0-MacOSX-x86_64.pkg 256.7 MiB 2013-09-20 05:04 Anaconda-1.7.0-MacOSX-x86_64.sh 223.3 MiB 2013-09-20 11:00 Anaconda-1.7.0-Windows-x86.exe 280.6 MiB 2013-09-20 11:11 Anaconda-1.7.0-Windows-x86_64.exe,请问我应该安装哪一个?
07-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值