From 4753900e429f7e9369314db1d2431dd65adad752 Mon Sep 17 00:00:00 2001 From: Yashyasvi Agarwal Date: Thu, 10 Oct 2019 10:45:22 +0530 Subject: [PATCH] added CHEFINSQ added CHEFINSQ question from september long challenge 2019 --- CHEFINSQ.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 CHEFINSQ.py diff --git a/CHEFINSQ.py b/CHEFINSQ.py new file mode 100644 index 0000000..2d943b9 --- /dev/null +++ b/CHEFINSQ.py @@ -0,0 +1,30 @@ +#function to call recursive function and return the final solution to it's caller function +def count_sets_dp(arr,total,n,k): + mem={} + return dp(arr,total,n-1,mem,k) + +#recursive and dynamic programming function to generate subsequences and find the eligible subsequence +def dp(arr,total,i,mem,k): + key=str(total)+':'+str(k)+':'+str(i) + if key in mem: + return mem[key] + if total==0 and k==0: + return 1 + elif total<0 or k<0: + return 0 + elif i<0: + return 0 + elif total