This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example : | |
| # a = [1,2,3] | |
| # x = subset(a) * x=> [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]] | |
| # x.sort() * x => [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]] | |
| def subset(a): | |
| if a == []: | |
| return [[]] | |
| i = subset(a[1:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static int productOfSubsetSums(int arr[], int n) | |
| { | |
| int ans = 1; | |
| for (int i = 0; i < n; ++i ) | |
| ans = ans * (arr[i] + 1); | |
| return ans-1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % m is the matrix | |
| % to check if a matrix has inverse or not, use det(). | |
| if det(m)~=0 | |
| % The matrix has inverse | |
| minv = inv(m); | |
| else | |
| % The matrix doesn't has inverse | |
| % Approximate the inverse using SVD | |
| [U,S,V] = svd(m); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function | |
| # PRINT VALUE FROM S to N | |
| s = int(raw_input()) | |
| n = int(raw_input()) | |
| print(*range(s,n+1),sep=' ') |
NewerOlder