HDU 5000 Clone(鞍山網路賽D題),hdu鞍山

來源:互聯網
上載者:User

HDU 5000 Clone(鞍山網路賽D題),hdu鞍山
HDU 5000 Clone

這場就出了3題。。就坑在這題上了,還好保住了名額

思路:要推出最大值的時候,每個人的屬性和必然相同,並且這個和必然是所有和 / 2,這樣的話,問題轉化為給n個數字,要組合成sum / 2有多少種方法,就用dp背包推一遍就可以得解了。

現場的時候就沒推出sum / 2就是答案

代碼:

#include <cstdio>#include <cstring>const int MOD = 1000000007;const int N = 2005;int t, n, dp[N], T[N];int main() {scanf("%d", &t);while (t--) {scanf("%d", &n);int sum = 0;for (int i = 1; i <= n; i++) {scanf("%d", &T[i]);sum += T[i];}sum /= 2;memset(dp, 0, sizeof(dp));dp[0] = 1;for (int i = 1; i <= n; i++) {for (int k = sum; k >= 0; k--) {for (int j = 1; j <= T[i]; j++) {if (k - j < 0) break;dp[k] = (dp[k] + dp[k - j]) % MOD;}}}printf("%d\n", dp[sum]);}return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.