algebra

Calculate multinomial coefficient

烂漫一生 提交于 2019-12-04 15:43:49
I want to calculate multinomial coefficient mod 1e9 + 7. It equals: n! / (k0! * k1! * k2 * ... * km!) In my case m = 3, k0 + k1 + k2 = n, so it would be: n! / (k0! * k1! * k2!) My code for this: .... long long k2 = n - k1 - k0; long long dans = fact[n] % MOD; long long tmp = fact[i] % MOD; tmp = (tmp * fact[j]) % MOD; tmp = (tpm * fact[k]) % MOD; res = (fact[n] / tmp) % MOD; // mb mistake is here... cout << res; fact[i] - factorial of i mod 1e9+7 It does not work on big tests I hope I'm not linkfarming here, but here is a process of work, to solve your problem : Naive implementations will

Equation Solvers for linear mathematical equations

末鹿安然 提交于 2019-12-04 12:48:43
I need to solve a few mathematical equations in my application. Here's a typical example of such an equation: a + b * c - d / e = a Additional rules: b % 10 = 0 b >= 0 b <= 100 Each number must be integer ... I would like to get the possible solution sets for a, b, c, d and e. Are there any libraries out there , either open source or commercial, which I can use to solve such an equation ? If yes, what kind of result do they provide? Solving linear systems can generally be solved using linear programming. I'd recommend taking a look at Boost uBLAS for starters - it has a simple triangular

Distance from a point to a polyhedron or to a polygon

£可爱£侵袭症+ 提交于 2019-12-04 12:01:18
问题 I have a surface which is a polyhedron and I want to find the minimal distance between it and a given point P . Since the polyhedron is defined by many polygons in a 3d space, one way that occurs to me is to compare the distance to each polygon and choose the shortest distance. Still I am not sure about it. 回答1: Implementations of Gilbert–Johnson–Keerthi: http://www.comlab.ox.ac.uk/stephen.cameron/distances/gjk2.4/ http://code.google.com/p/gjkd/ 来源: https://stackoverflow.com/questions/2433298

Generated methods for polynomial evaluation

独自空忆成欢 提交于 2019-12-04 08:16:07
I'm trying to come up with an elegant way to handle some generated polynomials. Here's the situation we'll focus on (exclusively) for this question: order is a parameter in generating an n th order polynomial, where n:=order + 1. i is an integer parameter in the range 0..n The polynomial has zeros at x_j, where j = 1..n and j ≠ i (it should be clear at this point that StackOverflow needs a new feature or it's present and I don't know it) The polynomial evaluates to 1 at x_i. Since this particular code example generates x_1 .. x_n, I'll explain how they're found in the code. The points are

Custom compile-time checks

此生再无相见时 提交于 2019-12-04 06:36:58
问题 I don´t think that this question has (or can) been answered, or at least I didn´t find the answer: is it possible to create custom compile-time checks? The specific situation is that I am programming a quantum spaces calculator, and while you could have vectors (1,0,0) and (1,0), I should modify certain operations between them as they belong to certain spaces. Even more, you could have (1,0) and (1,0) but neither of them belonging to the same spaces, so the operations between them would be

Books & resources to teach myself Linear Algebra [closed]

吃可爱长大的小学妹 提交于 2019-12-04 03:52:54
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I'm looking for books and resource to teach myself linear algebra to be used in 3D graphics programming. I prefer practical approaches to teaching over theoretical (even though math is what, 99.99% theory?) ones, so the dream resource

How could I implement logical implication with bitwise or other efficient code in C?

早过忘川 提交于 2019-12-04 02:41:46
I want to implement a logical operation that works as efficient as possible. I need this truth table: p q p → q T T T T F F F T T F F T This, according to wikipedia is called " logical implication " I've been long trying to figure out how to make this with bitwise operations in C without using conditionals. Maybe someone has got some thoughts about it. Thanks FYI, with gcc-4.3.3: int foo(int a, int b) { return !a || b; } int bar(int a, int b) { return ~a | b; } Gives (from objdump -d): 0000000000000000 <foo>: 0: 85 ff test %edi,%edi 2: 0f 94 c2 sete %dl 5: 85 f6 test %esi,%esi 7: 0f 95 c0

How to solve Linear Diophantine equations in programming?

谁说胖子不能爱 提交于 2019-12-03 14:04:49
问题 I have read about Linear Diophantine equations such as ax+by=c are called diophantine equations and give an integer solution only if gcd(a,b) divides c . These equations are of great importance in programming contests. I was just searching the Internet, when I came across this problem. I think its a variation of diophantine equations. Problem : I have two persons,Person X and Person Y both are standing in the middle of a rope. Person X can jump either A or B units to the left or right in one

Initial algebra for rose trees

人盡茶涼 提交于 2019-12-03 12:41:25
As far as I understand, recursive data types from Haskell correspond to initial algebras of endofunctors from the Hask category [ 1 , 2 ]. For example: Natural numbers, data Nat = Zero | Succ Nat , correspond to the initial algebra of the endofunctor F(-) = 1 + (-) . Lists, data List a = Nil | Cons a (List a) , correspond to the initial algebra of the endofunctor F(A, -) = 1 + A × (-) . However, it's not clear to me what the endofunctor corresponding to the rose trees should be: data Rose a = Node a (List (Rose a)) What confuses me is that there are two recursions: one for the rose tree and

How to solve Linear Diophantine equations in programming?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 04:58:08
I have read about Linear Diophantine equations such as ax+by=c are called diophantine equations and give an integer solution only if gcd(a,b) divides c . These equations are of great importance in programming contests. I was just searching the Internet, when I came across this problem. I think its a variation of diophantine equations. Problem : I have two persons,Person X and Person Y both are standing in the middle of a rope. Person X can jump either A or B units to the left or right in one move. Person Y can jump either C or D units to the left or right in one move. Now, I'm given a number K