mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Wrap lines that go beyond GitHub Editor (#1925)
* Wrap lines that go beyond GiHub Editor * flake8 --count --select=E501 --max-line-length=127 * updating DIRECTORY.md * Update strassen_matrix_multiplication.py * fixup! Format Python code with psf/black push * Update decision_tree.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -4,10 +4,9 @@ This is a Python implementation for questions involving task assignments between
|
||||
Here Bitmasking and DP are used for solving this.
|
||||
|
||||
Question :-
|
||||
We have N tasks and M people. Each person in M can do only certain of these tasks. Also a person can do only one task and a task is performed only by one person.
|
||||
We have N tasks and M people. Each person in M can do only certain of these tasks. Also
|
||||
a person can do only one task and a task is performed only by one person.
|
||||
Find the total no of ways in which the tasks can be distributed.
|
||||
|
||||
|
||||
"""
|
||||
from collections import defaultdict
|
||||
|
||||
@ -25,7 +24,8 @@ class AssignmentUsingBitmask:
|
||||
|
||||
self.task = defaultdict(list) # stores the list of persons for each task
|
||||
|
||||
# final_mask is used to check if all persons are included by setting all bits to 1
|
||||
# final_mask is used to check if all persons are included by setting all bits
|
||||
# to 1
|
||||
self.final_mask = (1 << len(task_performed)) - 1
|
||||
|
||||
def CountWaysUtil(self, mask, task_no):
|
||||
@ -45,7 +45,8 @@ class AssignmentUsingBitmask:
|
||||
# Number of ways when we don't this task in the arrangement
|
||||
total_ways_util = self.CountWaysUtil(mask, task_no + 1)
|
||||
|
||||
# now assign the tasks one by one to all possible persons and recursively assign for the remaining tasks.
|
||||
# now assign the tasks one by one to all possible persons and recursively
|
||||
# assign for the remaining tasks.
|
||||
if task_no in self.task:
|
||||
for p in self.task[task_no]:
|
||||
|
||||
@ -53,7 +54,8 @@ class AssignmentUsingBitmask:
|
||||
if mask & (1 << p):
|
||||
continue
|
||||
|
||||
# assign this task to p and change the mask value. And recursively assign tasks with the new mask value.
|
||||
# assign this task to p and change the mask value. And recursively
|
||||
# assign tasks with the new mask value.
|
||||
total_ways_util += self.CountWaysUtil(mask | (1 << p), task_no + 1)
|
||||
|
||||
# save the value.
|
||||
@ -85,6 +87,7 @@ if __name__ == "__main__":
|
||||
)
|
||||
"""
|
||||
For the particular example the tasks can be distributed as
|
||||
(1,2,3), (1,2,4), (1,5,3), (1,5,4), (3,1,4), (3,2,4), (3,5,4), (4,1,3), (4,2,3), (4,5,3)
|
||||
(1,2,3), (1,2,4), (1,5,3), (1,5,4), (3,1,4),
|
||||
(3,2,4), (3,5,4), (4,1,3), (4,2,3), (4,5,3)
|
||||
total 10
|
||||
"""
|
||||
|
@ -2,10 +2,12 @@
|
||||
Author : Turfa Auliarachman
|
||||
Date : October 12, 2016
|
||||
|
||||
This is a pure Python implementation of Dynamic Programming solution to the edit distance problem.
|
||||
This is a pure Python implementation of Dynamic Programming solution to the edit
|
||||
distance problem.
|
||||
|
||||
The problem is :
|
||||
Given two strings A and B. Find the minimum number of operations to string B such that A = B. The permitted operations are removal, insertion, and substitution.
|
||||
Given two strings A and B. Find the minimum number of operations to string B such that
|
||||
A = B. The permitted operations are removal, insertion, and substitution.
|
||||
"""
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user