Given measured environmental factors and one-operation definitions, compute each factor's partial derivative of HAPPY and print it as a reduced fraction.
Medium6Dynamic programmingDFSMathRecursionNo attempts yetTime limit1sMemory limit512 MBHuman moods are hard to predict. Even in the same setting, reactions differ with personality and experience, and someone who cried all day may smile comfortably the next day.
Dr. Seojisu, who develops personalized AI systems, starts from one hypothesis.
"If we know the factors that shaped a person's happiness today and how those factors relate to each other, we can predict tomorrow's mood."
Factors that shape the mood fall into two kinds.
An environmental factor can be measured numerically through observation. The day's temperature, the number of friends met, and hours of sleep are examples.
A complex factor is determined by combining two different factors through one operation. For example, if study satisfaction A equals the number of classes taken B plus fatigue C, it is written as A=B+C. Happiness itself can be seen as one such complex factor.
Suppose we know today's measured values of all environmental factors and every relation between the factors. For each factor we want its influence on happiness, defined as the instantaneous rate of change of happiness with respect to that factor.
For example, let happiness HAPPY be the product HAPPY=A×B of income A and work satisfaction B, with today's measurements A=17 and B=13. Then HAPPY=221, the influence of A is 13, the influence of B is 17, and the influence of HAPPY on itself is 1.
Given the kinds of factors and their relations, write a program that computes the influence of every factor.
The first line gives N, the number of factors. Each of the following N lines describes one factor.
{name} E {measured value}.{name} {operation} {operand 1} {operand 2}.Every input satisfies the following.
Print N lines, one per factor, sorted by factor name in lexicographic order. Each line has the form {name} {influence}.
MONEY -1/4.0/1.The second and third public test cases do not appear in the Small subtask.