ABC --011-A & B & C

AtCoder ABC 011 A&B&C AtCoder - 011

A ――What month is next month?

--If it's December, next is January --January-November, next is + January

	private void solveA() {
		int n = nextInt();

		out.println(n == 12 ? 1 : n + 1);
	}

B-Name confirmation

	private void solveB() {
		char[] n = next().toCharArray();
		for (int i = 0; i < n.length; i++) {
			if (i == 0) {
				n[i] = Character.toUpperCase(n[i]);
			} else {
				n[i] = Character.toLowerCase(n[i]);
			}

		}

		out.println(new String(n));
	}

C-123 subtraction

Recursion

	private void solveC2() {
		int n = nextInt();
		int ng1 = nextInt();
		int ng2 = nextInt();
		int ng3 = nextInt();

		Map<String, Boolean> memo = new HashMap<String, Boolean>();
		boolean res = recursiveC2(ng1, ng2, ng3, 0, n, memo);
		out.println(res ? "YES" : "NO");
	}

	private boolean recursiveC2(int ng1, int ng2, int ng3, int currentI, int currentNum, Map<String, Boolean> memo) {
		if (currentNum == ng1 || currentNum == ng2 || currentNum == ng3) {
			return false;
		}
		if (currentNum == 0) {
			return true;
		}
		if (currentI == 100) {
			return false;
		}
		if (memo.containsKey(currentI + ":" + currentNum)) {
			return memo.get(currentI + ":" + currentNum);
		}
		boolean res = false;
		res = res || recursiveC2(ng1, ng2, ng3, currentI + 1, currentNum - 1, memo);
		res = res || recursiveC2(ng1, ng2, ng3, currentI + 1, currentNum - 2, memo);
		res = res || recursiveC2(ng1, ng2, ng3, currentI + 1, currentNum - 3, memo);
		memo.put(currentI + ":" + currentNum, res);
		return res;
	}

DP

――Since I was able to AC by recursion, I tried to solve it with DP instead of practice -How many hands can you make numbers up to $ n-0 $ (`step [n + 1]`)? --Three patterns: $ n-1, n-2, n-3 $ ――If you get an NG number on the way, you can't adopt that pattern. --I'm skipping with continue --Success if you can finally create it with less than 100 moves

	private void solveC() {
		int n = nextInt();
		int ng1 = nextInt();
		int ng2 = nextInt();
		int ng3 = nextInt();
		if (n == ng1 || n == ng2 || n == ng3) {
			out.println("NO");
			return;
		}
		long[] step = new long[n + 1];
		Arrays.fill(step, Long.MAX_VALUE / 10);
		step[n] = 0;
		for (int i = n; i >= 0; i--) {
			if (i == ng1 || i == ng2 || i == ng3) {
				continue;
			}
			if (i + 1 <= n) {
				step[i] = Long.min(step[i + 1] + 1, step[i]);
			}
			if (i + 2 <= n) {
				step[i] = Long.min(step[i + 2] + 1, step[i]);
			}
			if (i + 3 <= n) {
				step[i] = Long.min(step[i + 3] + 1, step[i]);
			}
		}

		out.println(step[0] <= 100 ? "YES" : "NO");
	}

Recommended Posts

ABC --013-A & B & C
ABC --036-A & B & C
ABC --010 --A & B & C
ABC --028 --A & B & C
ABC --015 --A & B & C
ABC --128 --A & B & C
ABC --012-A & B & C
ABC --018 --A & B & C
ABC --017 --A & B & C
ABC --029- A & B & C
ABC --022 --A & B & C
ABC --019 --A & B & C
ABC --030- A & B & C
ABC --127 --A & B & C
ABC --007 --A & B & C
ABC --132- A & B & C
ABC --026 --A & B & C
ABC --014- A & B & C
ABC --016 --A & B & C
ABC --011-A & B & C
ABC --031 --A & B & C
ABC --021 --A & B & C
ABC --025 --A & B & C
ABC --024 --A & B & C
ABC --027 --A & B & C
ABC --080- A & B & C
ABC --129- A & B & C & D
ABC --133- A & B & C & D
ABC --122 --A & B & C & D
ABC --125- A & B & C & D
ABC --130- A & B & C & D
ABC --126 --A & B & C & D
ABC --134- A & B & C & D & E
ABC --131- A & B & C & D & E
diverta 2019 Programming Contest A & B & C & D
AtCoder Beginner Contest 169 A, B, C with ruby
atcoder ABC113 C problem
ABC093 C --Same Integers
atcoder ABC115 C problem
AtCoder Beginner Contest 170 A, B, C up to ruby
A person writing C ++ tried writing Java
Make a SOAP call in C #
Call a C function from Swift
NLP4J [006-034] 100 language processing knocks with NLP4J # 34 "A B"