zawatins-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub zawa-tin/zawatins-library

:warning: max-plus-semiring (max+)
(src/utility/semiring/max-plus-semiring.hpp)

概要

$\R\ \cup\ {-\infin }$ 上での $\max$ と $+$ についての半環 を扱う構造体。トロピカル半環 とも呼ばれる。

機能

zawa::normal_semiring<T>

T id_add

T id_mul

T add(const T& a, const T& b)

T mul(const T& a, const T& b)

Code

#pragma once

#include <algorithm>
#include <climits>

namespace zawa {

template <class dat_type>
struct maxplus_semiring {
	using T = dat_type;
	static constexpr T id_add = -std::numeric_limits<T>::max();
	static constexpr T id_mul = 0;
	static T add(const T& a, const T& b) {
		return std::max(a, b);
	}
	static T mul(const T& a, const T& b) {
		if (b > 0 or a > id_add - b) {
			return a + b;
		}
		else {
			return id_add;
		}
	}
};

} // namespace zawa
#line 2 "src/utility/semiring/max-plus-semiring.hpp"

#include <algorithm>
#include <climits>

namespace zawa {

template <class dat_type>
struct maxplus_semiring {
	using T = dat_type;
	static constexpr T id_add = -std::numeric_limits<T>::max();
	static constexpr T id_mul = 0;
	static T add(const T& a, const T& b) {
		return std::max(a, b);
	}
	static T mul(const T& a, const T& b) {
		if (b > 0 or a > id_add - b) {
			return a + b;
		}
		else {
			return id_add;
		}
	}
};

} // namespace zawa
Back to top page