結果

問題 No.560 ふしぎなナップサック
ユーザー CleyLCleyL
提出日時 2020-03-16 19:19:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 429 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 70,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 01:08:52
合計ジャッジ時間 1,259 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
using namespace std;

double dp[1000][3];
int main(){
	int m,n;cin>>m>>n;
	if(!n){
		cout << m << endl;
		return 0;
	}
	dp[0][0] = m*2;
	dp[0][1] = m+1;
	dp[0][2] = 0;
	for(int i = 1; n > i; i++){
		double t = (dp[i-1][0]+dp[i-1][1]+dp[i-1][2])/3;
		dp[i][0] = t*2;
		dp[i][1] = t+1;
		dp[i][2] = 0;
	}
	cout << fixed << setprecision(10) << (dp[n-1][0]+dp[n-1][1]+dp[n-1][2])/3.0 << endl;
}
0