Home Backend Development Python Tutorial pytyon 带有重复的全排列

pytyon 带有重复的全排列

Jun 06, 2016 am 11:27 AM
Full arrangement repeat

代码如下:


from sys import argv
script, start, end = argv
vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ans = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
def dfs(cur, m):
 ans[cur] = m
 if cur == int(end) - int(start) + 1:
  for i in xrange(int(start), int(end) + 1):
   print ans[i],
  return
 cur = cur + 1
 for i in xrange(int(start), int(end) + 1):
  dfs(cur, i)
  print
dfs(0, start) 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
How to solve the problem of infinite loop of opening web pages in Edge browser How to solve the problem of infinite loop of opening web pages in Edge browser Dec 25, 2023 pm 01:19 PM

Many friends who use the edge browser on win10 have encountered the problem of web pages opening repeatedly, which is a headache. So how to solve it? Let’s take a look at the detailed solutions below. What to do if the edge browser keeps opening web pages repeatedly: 1. Enter the edge browser and click the three dots in the upper right corner. 2. Click "Settings" in the taskbar. 3. Find "Microsoft edge opening method". 4. Click the drop-down menu and select "Start Page". 5. Restart the browser after completion to solve the problem.

How to extract only one piece of duplicate data in Oracle database? How to extract only one piece of duplicate data in Oracle database? Mar 09, 2024 am 09:03 AM

How to extract only one piece of duplicate data in Oracle database? In daily database operations, we often encounter situations where we need to extract duplicate data. Sometimes we want to find one of the duplicate data instead of listing all the duplicate data. In Oracle database, we can achieve this purpose with the help of some SQL statements. Next, we will introduce how to extract only one piece of duplicate data from the Oracle database and provide specific code examples. 1. Use ROWID function ROWID is Ora

Why does the same event trigger bubbling twice? Why does the same event trigger bubbling twice? Feb 19, 2024 pm 10:34 PM

Why does the same bubbling event happen twice? Event bubbling is a common event delivery mechanism in browsers. When an element triggers an event, the event will be passed from the triggered element to the upper elements in sequence until it is passed to the root element of the document. This process is like bubbles bubbling in water, so it is called event bubbling. However, sometimes we find that the same bubbling event occurs twice. Why is this? There are two main reasons: event registration and event processing. First, we need to make it clear that the event

Why does event bubbling trigger multiple times? Why does event bubbling trigger multiple times? Feb 24, 2024 pm 08:33 PM

Why is the event bubbling triggered twice? In front-end development, we often encounter the concept of event bubbling. Event bubbling means that when a specific event of an element is triggered on the page, the event will be passed layer by layer to the upper element until it is finally passed to the document object. However, sometimes we may encounter the problem of event bubbling and triggering twice, even if we only bind the event listener once. So why does the phenomenon of repeated triggering occur? Let’s dive into the possible reasons below. First, we need to clarify the concept of event risk

Solving persistent recurring issues caused by win7 hardware or software changes Solving persistent recurring issues caused by win7 hardware or software changes Dec 29, 2023 pm 01:53 PM

Recently, the editor has discovered that many win7 users have encountered the problem that the system keeps repeatedly prompting that hardware or software has been changed. If you encounter this problem, don't worry. First try to restore the last settings. If that doesn't work, you can delete the driver in safe mode. Finally, we have a way to reinstall the system. Let’s take a look together below. Win7 has changed the hardware or software and keeps repeating the solution. Method 1. Press "F8" when booting to enter the advanced options, and then select the "Last Known Good Configuration" as shown in the figure. Method 2 1. If restoring the correct configuration does not work, you can Enter the advanced options according to the above method, and then enter "Safe Mode" 2. In safe mode, delete the software, drivers, etc. installed or updated during the last normal use one by one. Method 3 1. If

Implement C++ full permutation of a given string using STL Implement C++ full permutation of a given string using STL Sep 01, 2023 pm 11:33 PM

A permutation of a string is formed when the characters of a given string are rearranged in any form. For example, in this tutorial, we will discuss how to print all permutations of a given string using C++’s Standard Template Library Input:s="ADT" Output:"ADT","ATD","DAT","DTA", "TAD",&ldquo

How to use backtracking to achieve an efficient solution to the full permutation problem in PHP? How to use backtracking to achieve an efficient solution to the full permutation problem in PHP? Sep 19, 2023 am 11:53 AM

How to use backtracking to achieve an efficient solution to the full permutation problem in PHP? The backtracking method is an algorithm commonly used to solve permutation and combination problems, and can search for all possible solutions within a limited time. In PHP, we can use backtracking to solve the full permutation problem and find an efficient solution. The total permutation problem is a classic permutation and combination problem, whose goal is to find all possible permutations given a set of different elements. For example, for the set of elements {1,2,3}, all possible arrangements are {1,

Make binary strings equal by repeatedly replacing the second bit Make binary strings equal by repeatedly replacing the second bit Sep 17, 2023 pm 07:41 PM

In this problem, we need to convert bin1 string to bin2 string by replacing the second character of bin1 string with the minimum or maximum of the first and second characters and removing the first characters. Since we need to remove the first character, we need to ensure that the last len2−1 characters in the two strings are the same. Additionally, we need to make sure that we can get the first character of the second string by performing the given operation on the starting character of the bin1 string. Problem Statement - We are given bin1 and bin2 binary strings of length len1 and len2 respectively. We need to check if we can convert bin1 string to bin2 string by following operation. Use bin1 string

See all articles