Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- public static class SumOfK
- {
- public static int? chooseBestSum(int t, int k, List<int> ls) {
- int? ans = null;
- System.Console.WriteLine(ls.Count);
- if(k != 0 && ls.Count == 0){
- return null;
- }
- for(int i = 0; i < ls.Count; i++){
- if(k == 0){
- return 0;
- }
- var ls2 = new List<int>(ls);
- ls2.RemoveAt(i);
- System.Console.WriteLine(ls2.Count);
- var sum = chooseBestSum(t-ls[i], k - 1, ls2);
- if(sum + ls[i] <= t){
- sum +=ls[i];
- }else{
- continue;
- }
- if(ans == null || sum > ans){
- ans = sum;
- }
- }
- return ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement