蓝桥杯 第七届省赛试题 剪邮票

<div id="post_content_86165038147" class="d_post_content j_d_post_content  clearfix">            剪邮票

如【图1.jpg】, 有12张连在一起的12生肖的邮票。
现在你要从中剪下5张来,要求必须是连着的。
(仅仅连接一个角不算相连)
比如,【图2.jpg】,【图3.jpg】中,粉红色所示部分就是合格的剪取。

请你计算,一共有多少种不同的剪取方法。

请填写表示方案数目的整数。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。

<img style="cursor: url("http://tb2.bdstatic.com/tb/static-pb/img/cur_zin.cur"), pointer;" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=2e6a1bf805087bf47dec57e1c2d2575e/f7a2e8c451da81cb0a24a77e5566d0160b24318a.jpg" height="319" width="412" alt="" />
<img style="cursor: url("http://tb2.bdstatic.com/tb/static-pb/img/cur_zin.cur"), pointer;" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=26cc5ec927a446237ecaa56aa8237246/293cb7025aafa40f0015ea6eac64034f7af019f9.jpg" height="319" width="412" alt="" />
<img style="cursor: url("http://tb2.bdstatic.com/tb/static-pb/img/cur_zin.cur"), pointer;" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=de82bcb75e82b2b7a79f39cc01accb0a/58c44ef40ad162d98d1546af16dfa9ec8813cdd2.jpg" height="319" width="412" alt="" /></div>


package com.diqijie.shengsai;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;

/**
 * @author leibaobao 剪邮票 
 * 解: 深搜,效率不是很高,反正是填空题
 */
public class _7 {
	public static int count = 0;
	public static int [] a = new int[5];
	public static HashSet<String> hashset = new HashSet<String>();
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for(a[0] = 0; a[0] < 12; a[0]++)
			for(a[1] = a[0]+1; a[1] < 12; a[1]++)
				for(a[2] = a[1]+1; a[2] < 12; a[2]++)
					for(a[3] = a[2]+1; a[3] < 12; a[3]++)
						for(a[4] = a[3]+1; a[4] < 12; a[4]++)
							if(jus()){
								hashset.add(""+a[0]+a[1]+a[2]+a[3]+a[4]);
							}
		System.out.println(hashset.size());
	}
	private static boolean jus() {
		// TODO Auto-generated method stub
		boolean flag[] = new boolean[5];
		dfs(flag,0);
		return flag[0]&&flag[1]&&flag[2]&&flag[3]&&flag[4];
	}

	private static void dfs(boolean[] flag,int n) {
		// TODO Auto-generated method stub
		flag[n] = true;
		for(int i = 0; i < 5; i++){
			//加一减一要在同一行、加四减四要在同一列
			if(!flag[i] && (a[i]/4 == a[n]/4) && (a[i] == a[n] - 1 || a[i] == a[n] + 1)){
				dfs(flag,i);
			}
			if (!flag[i] && (a[i]%4 == a[n]%4) && (a[i] == a[n] - 4 || a[i] == a[n] + 4)){
				dfs(flag,i);
			}
		}	
	}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值