dynamic-programming

Convert EntityReference to Entity

徘徊边缘 提交于 2019-12-20 12:35:43
问题 Does anyone know how can Convert EntityReference to Entity. protected override void Execute(CodeActivityContext executionContext) { [Input("Email")] [ReferenceTarget("email")] public InArgument<Entity> EMail { get; set; } Entity MyEmail = EMail.Get<Entity>(executionContext); This give me an error. Cannot convert this. 回答1: The shortest answer to your questions is to query the database for the entity that's pointed out (referred to) by the entity reference. I've always viewed entity references

Algorithm that balances the number of elements in a subinterval of an array?

瘦欲@ 提交于 2019-12-20 11:36:11
问题 Lets say you have an array with 4 different types of elements. 1 1 2 3 1 2 2 3 3 4 4 1. I want to find the longest subinterval that results in an equal number of each elements and the largest total number of elements. In this case, it would be 1 1 2 3 1 2 2 3 3 because this results in 3 twos, 3 threes, and 3 ones. I believe this is some sort of modified dynamic programming, or something that requires prefix sums but I am not too sure. Can someone give me insight on how to start? 回答1: #!/usr

Dynamic programming - Coin change decision

随声附和 提交于 2019-12-20 09:13:28
问题 I'm reviewing some old notes from my algorithms course and the dynamic programming problems are seeming a bit tricky to me. I have a problem where we have an unlimited supply of coins, with some denominations x1, x2, ... xn and we want to make change for some value X. We are trying to design a dynamic program to decide whether change for X can be made or not (not minimizing the number of coins, or returning which coins, just true or false). I've done some thinking about this problem, and I

Given a list of numbers and a number k, return whether any two numbers from the list add up to k

安稳与你 提交于 2019-12-20 09:08:22
问题 This question was asked in the Google programming interview. I thought of two approaches for the same: Find all the subsequences of length. While doing so compute the sum and of the two elements and check if it is equal to k. If ye, print Yes, else keep searching. This is a brute Force approach. Sort the array in non-decreasing order. Then start traversing the array from its right end. Say we have the sorted array, {3,5,7,10} and we want the sum to be 17. We will start from element 10, index

Given a list of numbers and a number k, return whether any two numbers from the list add up to k

主宰稳场 提交于 2019-12-20 09:06:06
问题 This question was asked in the Google programming interview. I thought of two approaches for the same: Find all the subsequences of length. While doing so compute the sum and of the two elements and check if it is equal to k. If ye, print Yes, else keep searching. This is a brute Force approach. Sort the array in non-decreasing order. Then start traversing the array from its right end. Say we have the sorted array, {3,5,7,10} and we want the sum to be 17. We will start from element 10, index

Efficient table for Dynamic Programming in Haskell

亡梦爱人 提交于 2019-12-20 08:45:07
问题 I've coded up the 0-1 Knapsack problem in Haskell. I'm fairly proud about the laziness and level of generality achieved so far. I start by providing functions for creating and dealing with a lazy 2d matrix. mkList f = map f [0..] mkTable f = mkList (\i -> mkList (\j -> f i j)) tableIndex table i j = table !! i !! j I then make a specific table for a given knapsack problem knapsackTable = mkTable f where f 0 _ = 0 f _ 0 = 0 f i j | ws!!i > j = leaveI | otherwise = max takeI leaveI where takeI

Given a string of numbers and a number of multiplication operators, what is the highest number one can calculate?

戏子无情 提交于 2019-12-20 08:21:22
问题 This was an interview question I had and I was embarrassingly pretty stumped by it. Wanted to know if anyone could think up an answer to it and provide the big O notation for it. Question: Given a string of numbers and a number of multiplication operators, what is the highest number one can calculate? You must use all operators You cannot rearrange the string. You can only use the multiplication operators to calculate a number. E.g. String = "312" , 1 multiplication operator You can do 3*12 =

Dynamic programming - Algorithm to repair text where is all punctuation missing

不羁的心 提交于 2019-12-20 07:35:26
问题 This is description of my problem: I was thinking about start from left and add one letter and if it's word then check rest if could be separated to words (call recursion function). If yes then I have result if not then I would add one more letter to first word and so on. But this would take first smaller words and I guess it's needed to start with algorithm which check first longer words and then smaller. So I was thinking about start with whole word and then recursively check left part

Find number of subsets, that xor of remaining numbers equals to 0

﹥>﹥吖頭↗ 提交于 2019-12-20 06:38:44
问题 Given n numbers, find minimum number of subsets, which of remaining numbers is equal to 0. For example: {1,1,3,4,5} result is equal to 3, because we can delete subsets {1,3} (in two ways) or {3,4,5}. I'm searching for something faster than O(2^n) brute-force. 回答1: Let us consider a Dynamic Programming table of size n*m where m=10^4. We have an array of size n, such that 1 <= a[i] <= m . Now, D[i][j] = number of subsets such that xor of the set is j Here xor of the set means xor of all

Dynamic Programing approach for a subset sum

天涯浪子 提交于 2019-12-19 10:41:07
问题 Given the following Input 10 4 3 5 5 7 Where 10 = Total Score 4 = 4 players 3 = Score by player 1 5 = Score by player 2 5 = Score by player 3 7 = Score by player 4 I am to print players who's combine score adds to total so output can be 1 4 because player 1 + player 4 score = 3 + 7 -> 10 or output can be 2 3 because player 2 + player 3 score = 5 + 5 -> 10 So it is quite similar to a subset sum problem. I am relatively new to dynamic programing but after getting help on stackoverflow and