FOJ1174 Dice Stacking

Problem 1174 Dice Stacking

Accept: 69 Submit: 129
Time Limit: 1000 mSec Memory Limit : 32768 KB

Problem Description

Chun-Soo is playing a dice stacking game. Six faces of a die are squares of the same size; each face of a die has a number from 1 to 6. But, they are not standard dice because the sum of the numbers in the opposite faces may not always be 7.

The dice game is to stack several dice up in the order Die 1, Die 2, Die 3, from the base keeping the following rule: For each pair of consecutive dice, the number on the bottom of the top die must match the number on the top of the bottom die. In other words, the two faces that are together must have the same number. We are free to place the bottom die as we wish, so Die 1 can be set freely.

A long rectangular pillar which has 4 sides is created. We are trying to make one side have the maximum sum. (Note that after we rotate a die to fix the top face and bottom face, we can still rotate the die by 90, 180, or 270 degrees.) Write a program to find the maximum sum that one side can have.

Input

The first line of the input contains a single integer t (1 <= t <= 11), the number of test cases, followed by the input data for each test case. The first line for each test case contains an integer n (1 <= n <= 10,000), the number of dice. In the next lines, each line contains six integers for a die, by the order A, B, C, D, E, F, as in the following figure. There is a single space between two numbers. The number of dice is less than or equal to 10,000. It is possible for two dice to be the same.

Output

There should be one line per test case which contains the maximum sum of the numbers in one side.

Sample Input

152 3 1 6 5 43 1 2 4 6 55 6 4 1 3 21 3 6 2 4 54 1 6 5 2 3

Sample Output

29

Source

Iran 2004 

模拟题

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=10010;
int h[N][6],id[N][7],a[7]={5,3,4,1,2,0},judge[7];
int main(){
    int t,n,i,j,k;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(i=1;i<=n;i++){
            for(j=0;j<6;j++){
                scanf("%d",&h[i][j]);
                id[i][h[i][j]]=j;
            }
        }
        int ans=0;
        for(i=0;i<6;i++){
            memset(judge,0,sizeof(judge));
            int num=0;
            int tnum1=h[1][i];
            int tnum2=h[1][a[i]];
            judge[tnum1]=1;
            judge[tnum2]=1;
            for(j=6;j>0;j--){
                if(!judge[j]){
                    num+=j;
                    break;
                }
            }
            for(j=2;j<=n;j++){
                int tid=id[j][tnum2];
                tnum1=tnum2;
                tnum2=h[j][a[tid]];
                memset(judge,0,sizeof(judge));
                judge[tnum1]=1;
                judge[tnum2]=1;
                for(k=6;k>0;k--){
                    if(!judge[k]){
                        num+=k;break;
                    }
                }
            }
            if(num>ans)ans=num;
        }
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值