USACO2006 Backward Digit Sums /// 全排列 oj24212
题目大意:
给出杨辉三角的顶点值M和底边数的个数 N (1 ≤ N ≤ 10) ,求出底边各个数的值,其中各个数范围都为1 ~ N
当N=4,M=16时可能是这样的
3 1 2 4
4 3 6
7 9
16
Multiple test cases. For each case:
* Line 1: Two space-separated integers: N and the final sum.
For each case, output one line : An ordering of the integers 1..N that leads to the given sum. If there are multiple solutions, choose the one that is lexicographically least, i.e., that puts smaller numbers first.
4 16
3 1 2 4
Explanation of the sample:
There are other possible sequences, such as 3 2 1 4, but 3 1 2 4 is the lexicographically smallest.
3 1 2 4不是唯一解, 但是按字典序的最小解
N较小 直接暴力 用next_permutation()全排列函数 得出下一种排列 验证正确则跳出结束
#include <bits/stdc++.h>
using namespace std;
int a[],b[],n,m;
bool judge()
{
for(int k=n;k>;k--)
{
for(int i=;i<k;i++)
b[i]=b[i]+b[i+];
}
if(b[]==m) return ;
else return ;
}
void per()
{
do
{
for(int i=;i<=n;i++)
b[i]=a[i];
if(judge()) return;
}while(next_permutation(a+,a++n));
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=;i<=n;i++)
a[i]=i;
per();
for(int i=;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
} }
USACO2006 Backward Digit Sums /// 全排列 oj24212的更多相关文章
- BZOJ1653: [Usaco2006 Feb]Backward Digit Sums
1653: [Usaco2006 Feb]Backward Digit Sums Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 207 Solved: ...
- 1653: [Usaco2006 Feb]Backward Digit Sums
1653: [Usaco2006 Feb]Backward Digit Sums Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 285 Solved: ...
- Backward Digit Sums(暴力)
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5664 Accepted: 32 ...
- 【POJ - 3187】Backward Digit Sums(搜索)
-->Backward Digit Sums 直接写中文了 Descriptions: FJ 和 他的奶牛们在玩一个心理游戏.他们以某种方式写下1至N的数字(1<=N<=10). 然 ...
- P1118 [USACO06FEB]Backward Digit Sums G/S
P1118 [USACO06FEB]Backward Digit Sums G/S 题解: (1)暴力法.对1-N这N个数做从小到大的全排列,对每个全排列进行三角形的计算,判断是否等于N. 对每个 ...
- Backward Digit Sums(POJ 3187)
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5495 Accepted: 31 ...
- POJ3187 Backward Digit Sums 【暴搜】
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4487 Accepted: 25 ...
- POJ 3187 Backward Digit Sums 枚举水~
POJ 3187 Backward Digit Sums http://poj.org/problem?id=3187 题目大意: 给你一个原始的数字序列: 3 1 2 4 他可以相邻 ...
- (DFS、全排列)POJ-3187 Backward Digit Sums
题目地址 简要题意: 输入两个数n和m,分别表示给你1--n这些整数,将他们按一定顺序摆成一行,按照杨辉三角的计算方式进行求和,求使他们求到最后时结果等于m的排列中字典序最小的一种. 思路分析: 不难 ...
随机推荐
- 制作linux根文件系统
转载地址:http://wenku.baidu.com/view/2cb1b4707fd5360cba1adb14.html 2011十一月 24 转 嵌入式根文件系统制作 (3985) (0) 转自 ...
- 用java进行测试php写的接口
<?php /* * @Author: anchen * @Date: 2018-07-06 13:53:19 * @Last Modified by: anchen * @Last Modif ...
- Eclipse lombok get set方法报错
在maven仓库中找到 lombok jar包 如:C:\Program File\.m2\Repository\org\projectlombok\lombok\1.18.2\lombok-1.18 ...
- Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别 Pig
Hadoop生态上几个技术的关系与区别:hive.pig.hbase 关系与区别 Pig 一种操作hadoop的轻量级脚本语言,最初又雅虎公司推出,不过现在正在走下坡路了.当初雅虎自己慢慢退出pig的 ...
- gthub获得star指南
https://mp.weixin.qq.com/s/EmyK1Fm5MDWQcrUxP8Tcgg
- Linux关闭端口
1. 查看哪些端口被占用 $ netstat -anp | grep 2042 tcp 0 0 192.168.56.1:2042 0.0.0.0:* LISTEN 8974/python 2. 删 ...
- LeetCode 最小栈
题目链接:https://leetcode-cn.com/problems/min-stack/ 题目大意 略.并且题目中要求的操作都要 O(1) 实现. 分析 用 2 个栈,一个普通栈,一个单调栈. ...
- Array.prototype.slice.call()等几种将arguments对象转换成数组对象的方法
网站搬迁,给你带来的不便敬请谅解! http://www.suanliutudousi.com/2017/10/10/array-prototype-slice-call%E7%AD%89%E5%87 ...
- 使用ProxyBroker构建代理池
import asyncio from proxybroker import Broker async def show(proxies): while True: proxy = await pro ...
- Struts2入门示例(Myeclipse)
1.新建Web项目在lib导入struts-2.3.37核心基础jar包 2.在WebRoot新建2个JSP demo1.jsp <%@ page language="java&quo ...