HDU1584(蜘蛛牌)
蜘蛛牌
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2880 Accepted Submission(s): 1230
每组数据有一行,10个输入数据,数据的范围是[1,10],分别表示A到10,我们保证每组数据都是合法的。
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string.h>
using namespace std;
int a[],vis[];
int res;
int abs(int x)
{
return x<?-x:x;
}
void dfs(int dep,int sum)
{
if(sum>res)
{
return ;
}
if(dep==)
{
res=sum;
return ;
}
for(int i=;i<=;i++)
{
if(!vis[i])
{
vis[i]=;
for(int j=i+;j<=;j++)
{
if(!vis[j])
{
dfs(dep+,sum+abs(a[i]-a[j]));
break;
}
}
vis[i]=;
}
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
for(int i=;i<=;i++)
{
int x;
cin>>x;
a[x]=i;
}
res=0x3f3f3f3f;
memset(vis,,sizeof(vis));
dfs(,);
cout<<res<<endl;
}
return ;
}
HDU1584(蜘蛛牌)的更多相关文章
- HDU-1584 蜘蛛牌(dfs)
可以多看看. 蜘蛛牌 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- ACM学习历程—HDU1584 蜘蛛牌(动态规划 && 状态压缩 || 区间DP)
Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么这些牌也跟着一起 ...
- HDU1584:蜘蛛牌(DFS)
Problem Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么 ...
- 蜘蛛牌(hdu 1584 DFS)
蜘蛛牌 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- F - 蜘蛛牌(深度搜索)
Problem Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么 ...
- D - 蜘蛛牌
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- hdoj1584 蜘蛛牌 (区间型动态规划)
hdoj1584 分析: f[i][j] 表示 把一串牌 牌 i 到 j 摞为一摞时 所花费最少的步数. d[i][j] 表示把牌 i 挪到牌 j 上时需要走的步数(最初给的状态). 以一串牌 3~8 ...
- (step4.3.9)hdu 1584(蜘蛛牌——DFS)
题目大意:本体是中文题,可以直接在OJ上看 /* * 1584_2.cpp * * Created on: 2013年8月22日 * Author: Administrator */ #include ...
- HDU 1584(蜘蛛牌 DFS)
题意是在蜘蛛纸牌的背景下求 10 个数的最小移动距离. 在数组中存储 10 个数字各自的位置,用深搜回溯的方法求解. 代码如下: #include <bits/stdc++.h> usin ...
随机推荐
- Android 下的usb框架及功能点【转】
本文转载自:https://blog.csdn.net/tianruxishui/article/details/37902959 有关USB android框架的链接 http://blog.sin ...
- wampserver安装缺失vcruntime140.dll
wampserver安装缺失vcruntime140.dll,这是安装wamp时候经常遇到的一个问题,对于初学者来说很难解决,以前的百度经验很难解决,所以给大家一个可以用的. 方法/步骤 请先 ...
- Windows 2012 系统汉化
远程登录服务器 控制面板,选择“语言” (Windows 2012 自带的语言包 ) 此处需要等待 安装完成,选择中文 重启后 应该就不需要做其他的操作了
- ubuntu 的mysql 安装过程和无法远程的解决方案
ubuntu 的mysql 安装过程和无法远程的解决方案 安装完mysql-server启动mysqlroot@ubuntu:# /etc/init.d/mysql start (如果这个命令不可以, ...
- C#反射第二天
原文:http://blog.csdn.net/zhaoguiqun/article/details/5954720 1.什么是反射Reflection,中文翻译为 反射. 这是.Net中获取 ...
- 【转载】postgreSQL在linux中安装详解
.编译环境 Linux: CentOS 5.5 gcc: 4.1.2 1. 安装PostgreSQL 1) 解压postgresql-9.1.7.tar.bz2 #tar jxvf postgresq ...
- C# 6.0 (VS2015 CTP6)
/* C# 6.0 demo https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14 */ using ...
- 大视野 1012: [JSOI2008]最大数maxnumber(线段树/ 树状数组/ 单调队列/ 单调栈/ rmq)
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 9851 Solved: 4318[Submi ...
- GEF入门实例_总结_06_为编辑器添加内容
一.前言 本文承接上一节:GEF入门实例_总结_05_显示一个空白编辑器 在上一节我们为我们的插件添加了一个空白的编辑器,这一节我们将为此编辑器添加内容. 二.GEF的MVC模式 在此只简单总结一下, ...
- listening 1
It was regrettable that such great issues had to be the thrust and parry of a general election. But ...