This document contains mathematical equations and calculations involving variables and coefficients. Steps are shown to solve for unknown variables through algebraic manipulation and substitution of values into equations. The final lines indicate the solution was checked against the original problem.
- The document contains code and explanations for solving optimization problems using dynamic programming, including calculating minimum costs using a 2D array to store results.
- It describes applying dynamic programming to problems involving finding minimum costs for tasks that can be split into subtasks, with the overall cost determined by combining subtask costs.
- The code provided shows initializing a 2D array and using nested for loops to iterate through values, calculate minimum costs based on previous results, and store them in the 2D array to build up an optimal solution.
14. B問題 アルゴリズム
? どうやってコードにしよう?
– Nが奇数であるかどうかの判定
? A % B で、「AをBで割った余り」を求められる。
– 言語によっては%の代わりにmodだったりするから調べよう!
? if(N%2==1) で奇数判定出来る!
– C言語などはif(N%2)だけでも良い。
– これを使えば、答えの求め方は簡単!
int N ← input
int ans;
if(N%2 == 1) ans = N + 1;
else ans = N – 1;
output → ans
2016/3/12 14