#include #include #include #include #include #include #include // 内部定数 #define D_MOD 1000000007 // 除数(10の9乗+7) #define D_FISH_MAX 100005 // 最大魚数 #define D_FACT_MAX D_FISH_MAX // 最大階乗数 // 内部変数 static FILE *szpFpI; // 入力 static int siFCnt; // 魚数 static int siPCnt; // ポイ数 static int siFRate; // 破損率 static int si1Val[D_FISH_MAX]; // 価値[魚] static int si1SRate[D_FISH_MAX]; // 連続成功率 static int si1FRate[D_FISH_MAX]; // 連続失敗率 static int si1HRate[D_FISH_MAX * 2]; // 百分率(逆元) static int si1ModFact[D_FACT_MAX]; // 階乗リスト static int si1ModFactR[D_FACT_MAX]; // 階乗リスト(逆元) // 内部変数 - テスト用 #ifdef D_TEST static int siRes; static FILE *szpFpA; static int siTNo; #endif // 出力 int fOut( char *pcpLine // 1行 ) { char lc1Buf[1024]; #ifdef D_TEST fgets(lc1Buf, sizeof(lc1Buf), szpFpA); if (strcmp(lc1Buf, pcpLine)) { siRes = -1; } #else printf("%s", pcpLine); #endif return 0; } // べき乗 - 取得 int fGetModPower( int piBase // 基数 , int piIdx // 指数 ) { // 平方リスト - 作成 int li1Val[100]; li1Val[0] = piBase; int liCnt = 1; int liIdx = 1; while (piIdx > liIdx) { li1Val[liCnt] = (int)((long long)li1Val[liCnt - 1] * (long long)li1Val[liCnt - 1] % (long long)D_MOD); liCnt++; liIdx += liIdx; } // べき乗 - 取得 int liVal = 1; while (piIdx > 0) { if (piIdx >= liIdx) { piIdx -= liIdx; liVal = (int)((long long)liVal * (long long)li1Val[liCnt - 1] % (long long)D_MOD); } liCnt--; liIdx /= 2; } return liVal; } // 階乗リスト - 作成 int fMakeModFact( int piMax // 最大値 ) { int i; si1ModFact[0] = 1; si1ModFact[1] = 1; for (i = 2; i <= piMax; i++) { si1ModFact[i] = (int)((long long)si1ModFact[i - 1] * (long long)i % (long long)D_MOD); } return 0; } // 階乗リスト(逆元) - 作成 int fMakeModFactR( int piMax // 最大値 ) { int i; for (i = 0; i <= piMax; i++) { si1ModFactR[i] = fGetModPower(si1ModFact[i], D_MOD - 2); } return 0; } // 実行メイン int fMain( ) { int i; char lc1Buf[1024]; // 魚数・ポイ数・破損率 - 取得 fgets(lc1Buf, sizeof(lc1Buf), szpFpI); sscanf(lc1Buf, "%d%d%d", &siFCnt, &siPCnt, &siFRate); // 価値 - 取得 for (i = 1; i <= siFCnt; i++) { fscanf(szpFpI, "%d", &si1Val[i]); } fgets(lc1Buf, sizeof(lc1Buf), szpFpI); // 確率 - セット si1SRate[0] = 1; for (i = 1; i <= siFCnt; i++) { si1SRate[i] = (int)((long long)si1SRate[i - 1] * (long long)(100 - siFRate) % (long long)D_MOD); } si1FRate[0] = 1; for (i = 1; i <= siPCnt; i++) { si1FRate[i] = (int)((long long)si1FRate[i - 1] * (long long)siFRate % (long long)D_MOD); } si1HRate[0] = 1; for (i = 1; i <= siFCnt + siPCnt; i++) { si1HRate[i] = (int)((long long)si1HRate[i - 1] * (long long)100 % (long long)D_MOD); } for (i = 1; i <= siFCnt + siPCnt; i++) { si1HRate[i] = fGetModPower(si1HRate[i], D_MOD - 2); } // 階乗リスト - 作成 fMakeModFact(siFCnt + siPCnt); fMakeModFactR(siFCnt + siPCnt); // 期待値 - 取得 - 1~siFCnt-1 int liExp = 0; int liSum = 0; for (i = 1; i < siFCnt; i++) { liSum += si1Val[i]; liSum %= D_MOD; int liVal = liSum; liVal = (int)((long long)liVal * (long long)si1SRate[i] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1FRate[siPCnt] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1HRate[i + siPCnt] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1ModFact[i + siPCnt - 1] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1ModFactR[i] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1ModFactR[siPCnt - 1] % (long long)D_MOD); liExp += liVal; liExp %= D_MOD; } // 期待値 - 取得 - siFCnt liSum += si1Val[siFCnt]; liSum %= D_MOD; for (i = 0; i < siPCnt; i++) { int liVal = liSum; liVal = (int)((long long)liVal * (long long)si1SRate[siFCnt] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1FRate[i] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1HRate[siFCnt + i] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1ModFact[siFCnt - 1 + i] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1ModFactR[siFCnt - 1] % (long long)D_MOD); liVal = (int)((long long)liVal * (long long)si1ModFactR[i] % (long long)D_MOD); liExp += liVal; liExp %= D_MOD; } return liExp; } // 1回実行 int fOne( ) { int liRet; char lc1Buf[1024]; // 入力 - セット #ifdef D_TEST sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo); szpFpI = fopen(lc1Buf, "r"); sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo); szpFpA = fopen(lc1Buf, "r"); siRes = 0; #else szpFpI = stdin; #endif // 実行メイン liRet = fMain(); // 出力 sprintf(lc1Buf, "%d\n", liRet); fOut(lc1Buf); // 残データ有無 #ifdef D_TEST lc1Buf[0] = '\0'; fgets(lc1Buf, sizeof(lc1Buf), szpFpA); if (strcmp(lc1Buf, "")) { siRes = -1; } #endif // テストファイルクローズ #ifdef D_TEST fclose(szpFpI); fclose(szpFpA); #endif // テスト結果 #ifdef D_TEST if (siRes == 0) { printf("OK %d\n", siTNo); } else { printf("NG %d\n", siTNo); } #endif return 0; } // プログラム開始 int main() { #ifdef D_TEST int i; for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) { siTNo = i; fOne(); } #else fOne(); #endif return 0; }