poj比赛题1006
来源:互联网 发布:手机淘宝上怎么给差评 编辑:程序博客网 时间:2024/06/05 18:28
Cow Solitaire
Time Limit:3000MS Memory Limit:65536K
Total Submit:14 Accepted:8
Description
Late summer on the farm is a slow time, very slow. Betsy has little to do but play cow solitaire. For self-evident reasons, cow solitaire is not so challenging as any number of solitaire games played by humans.
Cow solitaire is played using an N x N (3 <= N <= 7) grid of ordinary playing cards with four suits (Clubs, Diamonds, Hearts, and Spaces) of 13 cards (Ace, 2, 3, 4, ..., 10, Jack, Queen, King). Cards are named with two characters: their value (A, 2, 3, 4, ..., 9, T, J, Q, K) followed by their suit (C, D, H, S). Below is a typical grid when N = 4:
8S AD 3C AC (Eight of Spades, Ace of Diamonds, etc.)
8C 4H QD QS
5D 9H KC 7H
TC QC AS 2D
To play this solitaire game, Betsy starts in the lower left corner (TC) and proceeds using exactly 2*N-2 moves of 'right' or 'up' to the upper right corner. Along the way, she accumulates points for each card (Ace is worth 1 point, 2 is worth 2 points, ..., 9 is worth 9 points, T is worth 10 points, J is 11, Q is 12, and K is 13) she traverses. Her goal is to amass the highest score.
If Betsy's path was TC-QC-AS-2D-7H-QS-AC, her score would be 10+12+1+2+7+12+1=45. Had she taken the left side then top (TC-5D-8C-8S-AD-3C-AC), her score would be 10+5+8+8+1+3+1=36, not as good as the other route. The best score for this grid is 69 points (TC-QC-9H-KC-QD-QS-AC => 10+12+9+13+12+12+1).Betsy wants to know the best score she can achieve. One of the geek cows once told her something about "working from the end back to the beginning," but she didn't understand what they meant.
Input
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 lists the cards on row i (row 1 is the top row) using N space-separated card names arranged in the obvious order.
Output
* Line 1: A single line with an integer that is the best possible score Betsy can achieve.
Sample Input
48S AD 3C AC8C 4H QD QS5D 9H KC 7HTC QC AS 2D
Sample Output
69
昨天迎来了我们队的第一次内部比赛,很郁闷,自己居然连一道题也没能做出,哎,不
愦为一个超级大菜鸟,老实说,对于平时松散习惯了的我,对于成为ACM的正式队员并没
有很强的欲望,但是,我不想一直做那菜鸟中的菜鸟,不甘心啦,,,,,,
在比赛中我犯了一个错误,那就是在一棵树上吊死了,整整4个小时,我知识把精力放
在了一道题上面,而那道题却是其中最难的一道,寒,,,,,,,
对于本题,与我当天上午做的一道题很类似,但是,还是让我在晚上折腾了很久才做出,
用了很多种错误的方法,最终还是回归到了动态规划的思想.
正确代码如下:
#include<iostream>
using namespace std;
int main()
{
char c,d;
int i,j,m,a[8][8];
cin>>m;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
cin>>c>>d;
if(c=='A') a[i][j]=1;
else if(c=='T') a[i][j]=10;
else if(c=='J') a[i][j]=11;
else if(c=='Q') a[i][j]=12;
else if(c=='K') a[i][j]=13;
else
a[i][j]=c-48;
}
}
int num[8]={0};
for(i=0;i<m;i++)
{
num[m-1]+=a[i][m-1];
for(j=m-2;j>=0;j--)
{
num[j]+=a[i][j];
if(num[j]<num[j+1]+a[i][j])
num[j]=num[j+1]+a[i][j];
}
}
for(i=1;i<m;i++)
for(j=0;j<i;j++)
num[i]+=a[m-1][j];
int max=0;
for(i=0;i<m;i++)
if(max<num[i])
max=num[i];
cout<<max;
return 0;
}
- poj比赛题1006
- poj象棋比赛(DP)
- poj 1285 确定比赛名次
- POJ 1285 确定比赛名次
- Poj 3071 Football (比赛对阵 概率DP)
- 射击比赛 (POJ 1719) 题解
- poj 3660 奶牛比赛 Floyd算法
- 搜索比赛A题
- 搜索比赛B题
- 搜索比赛C题
- 搜索比赛D题
- 搜索比赛E题
- 搜索比赛F题
- 比赛题(物理题)
- 比赛题号
- 比赛题号
- java比赛题
- 比赛
- 关于如何芯片级修硬件
- Sql Server数据恢复实例案例
- SQL Server 2008 的管理能力
- 每个新手都需要弄明白的问题
- 百分比的细节--容器背景图片篇
- poj比赛题1006
- 我的firefox插件
- 图的邻接矩阵实现(包括PRIM和DIJKSTRA算法)
- 共享内存
- 简单的页面时钟显示
- ASP.NET生成HTML页面
- SQL中CONVERT转化函数的用法,插入datetime类型
- 通用芯片和专用芯片之争
- 在开发WEB应用程序时, 如何提高WEB应用程序的性能. 主要把注意力集中在哪些地方..~~!