CF388C.Fox and Card Game

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.

The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.

Suppose Ciel and Jiro play optimally, what is the score of the game?

小狐狸雪儿正在和她的朋友小狐狸次郎玩一个卡牌游戏。桌面上有 nn 堆卡牌,每张卡牌上都有一个正整数。

两名玩家轮流进行操作,雪儿先手。在雪儿的回合中,她从任意一个非空堆的顶部取走一张卡牌;而在次郎的回合中,他从任意一个非空堆的底部取走一张卡牌。每位玩家都希望最大化自己所取卡牌上的数字之和。当所有堆均变为空时,游戏结束。

假设雪儿与次郎均以最优策略进行游戏,那么最终的得分(即雪儿所得总和)是多少?

输入格式

The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is s__i (1 ≤ s__i ≤ 100) — the number of cards in the i-th pile; then follow s__i positive integers _c_1, _c_2, ..., c__k, ..., c__s__i (1 ≤ c__k ≤ 1000) — the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)。接下来的 nn 行每行描述一堆牌:每行的第一个整数为 sis_i(1≤si≤1001 \leq s_i \leq 100),表示第 ii 堆牌的张数;随后是 sis_i 个正整数 c1,c2,…,ck,…,csic_1, c_2, \dots, c_k, \dots, c_{s_i}(1≤ck≤10001 \leq c_k \leq 1000),表示该堆牌从顶到底的牌面数字序列。

输出格式

Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.

输出两个整数:若两人均采取最优策略,则天音(Ciel)所持卡片的点数之和与次郎(Jiro)所持卡片的点数之和。

输入输出样例

  • 输入#1

    2
    1 100
    2 1 10

    输出#1

    101 10
  • 输入#2

    1
    9 2 8 6 5 9 4 7 1 3

    输出#2

    30 15
  • 输入#3

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

    输出#3

    18 18
  • 输入#4

    3
    3 1000 1000 1000
    6 1000 1000 1000 1000 1000 1000
    5 1000 1000 1000 1000 1000

    输出#4

    7000 7000

说明/提示

In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.

In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.

在第一个例子中,Ciel 将取走编号为 100 和 1 的卡片,Jiro 将取走编号为 10 的卡片。

在第二个例子中,Ciel 将取走编号为 2、8、6、5、9 的卡片,Jiro 将取走编号为 4、7、1、3 的卡片。

输入解题思路,AI测评打分。不知道怎么写?

首页