





'''simple docstring'''







from collections import defaultdict


class 					__a      :

							def __init__(							self							:     Dict       ,     __magic_name__							:     List[Any]       ,     __magic_name__							:     Dict   )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  total  # total no of tasks (N)

													# DP table will have a dimension of (2^M)*N
													# initially all values are set to -1
													UpperCAmelCase_			:      str     						=  [
													    [-1 for i in range(total + 1   )] for j in range(2 ** len(__magic_name__   )   )
													]

													UpperCAmelCase_			:      str     						=  defaultdict(__magic_name__   )  # 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
													UpperCAmelCase_			:      Any     						=  (1 << len(__magic_name__   )) - 1

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     str       ,     __magic_name__							:     Any   )					->       Optional[Any]:







													"""simple docstring"""
													# if mask == self.finalmask all persons are distributed tasks, return 1
													if mask == self.final_mask:
																			return 1

													# if not everyone gets the task and no more tasks are available, return 0
													if task_no > self.total_tasks:
																			return 0

													# if case already considered
													if self.dp[mask][task_no] != -1:
																			return self.dp[mask][task_no]

													# Number of ways when we don't this task in the arrangement
													UpperCAmelCase_			:      int     						=  self.count_ways_until(__magic_name__       ,     task_no + 1   )

													# 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]:
																									# if p is already given a task
																									if mask & (1 << p):
																															continue

																									# assign this task to p and change the mask value. And recursively
																									# assign tasks with the new mask value.
																									total_ways_util += self.count_ways_until(mask | (1 << p)       ,     task_no + 1   )

        # save the value.
													UpperCAmelCase_			:      Dict     						=  total_ways_util

													return self.dp[mask][task_no]



							def     UpperCAmelCase__	(							self							:     str       ,     __magic_name__							:     Optional[Any]   )					->       Tuple:







													"""simple docstring"""
													# Store the list of persons for each task
													for i in range(len(__magic_name__   )   ):
																			for j in task_performed[i]:
																									self.task[j].append(__magic_name__   )

        # call the function to fill the DP table, final answer is stored in dp[0][1]
													return self.count_ways_until(0       ,     1   )


if __name__ == "__main__":
					snake_case_     :       List[str]						=  5  # total no of tasks (the value of N)

					# the list of tasks that can be done by M persons.
					snake_case_     :       List[Any]						=  [[1, 3, 4], [1, 2, 5], [3, 4]]
					print(
					    AssignmentUsingBitmask(task_performed, total_tasks).count_no_of_ways(
					        task_performed
					    )
					)












'''simple docstring'''







import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()


class 					__a      (unittest.TestCase     ):

							@property
							def     UpperCAmelCase__	(							self							:     Dict   )					->       str:







													"""simple docstring"""
													torch.manual_seed(0   )
													UpperCAmelCase_			:      Optional[Any]     						=  UNetaDModel(
													    block_out_channels=(32, 64)       ,     layers_per_block=2       ,     sample_size=32       ,     in_channels=3       ,     out_channels=3       ,     down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')       ,     up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')       ,     )
													return model



							def     UpperCAmelCase__	(							self							:     Dict   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      List[Any]     						=  self.dummy_uncond_unet
													UpperCAmelCase_			:      Dict     						=  KarrasVeScheduler()

													UpperCAmelCase_			:      Union[str, Any]     						=  KarrasVePipeline(unet=__magic_name__       ,     scheduler=__magic_name__   )
													pipe.to(__magic_name__   )
													pipe.set_progress_bar_config(disable=__magic_name__   )

													UpperCAmelCase_			:      Dict     						=  torch.manual_seed(0   )
													UpperCAmelCase_			:      Optional[int]     						=  pipe(num_inference_steps=2       ,     generator=__magic_name__       ,     output_type='''numpy'''   ).images

													UpperCAmelCase_			:      Tuple     						=  torch.manual_seed(0   )
													UpperCAmelCase_			:      str     						=  pipe(num_inference_steps=2       ,     generator=__magic_name__       ,     output_type='''numpy'''       ,     return_dict=__magic_name__   )[0]

													UpperCAmelCase_			:      Union[str, Any]     						=  image[0, -3:, -3:, -1]
													UpperCAmelCase_			:      Optional[Any]     						=  image_from_tuple[0, -3:, -3:, -1]

													assert image.shape == (1, 32, 32, 3)
													UpperCAmelCase_			:      Dict     						=  np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]   )

													assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2
													assert np.abs(image_from_tuple_slice.flatten() - expected_slice   ).max() < 1E-2





@slow
@require_torch
class 					__a      (unittest.TestCase     ):

							def     UpperCAmelCase__	(							self							:     int   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      List[str]     						=  '''google/ncsnpp-celebahq-256'''
													UpperCAmelCase_			:      List[str]     						=  UNetaDModel.from_pretrained(__magic_name__   )
													UpperCAmelCase_			:      List[Any]     						=  KarrasVeScheduler()

													UpperCAmelCase_			:      Any     						=  KarrasVePipeline(unet=__magic_name__       ,     scheduler=__magic_name__   )
													pipe.to(__magic_name__   )
													pipe.set_progress_bar_config(disable=__magic_name__   )

													UpperCAmelCase_			:      Dict     						=  torch.manual_seed(0   )
													UpperCAmelCase_			:      Optional[Any]     						=  pipe(num_inference_steps=20       ,     generator=__magic_name__       ,     output_type='''numpy'''   ).images

													UpperCAmelCase_			:      Any     						=  image[0, -3:, -3:, -1]
													assert image.shape == (1, 2_56, 2_56, 3)
													UpperCAmelCase_			:      Optional[Any]     						=  np.array([0.5_7_8, 0.5_8_1_1, 0.5_9_2_4, 0.5_8_0_9, 0.5_8_7, 0.5_8_8_6, 0.5_8_6_1, 0.5_8_0_2, 0.5_8_6]   )

													assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2





